#262 bug
dave mankoff

Element.down() Does Not Always Match First Element

Reported by dave mankoff | August 2nd, 2008 @ 08:32 PM | in 1.6.1

When running Element.down() with multiple, comma separated css rules, it does not neccessarily match the first element found. Instead, it seems to run the first css rule and return the first result that finds. If that has no matches, then and only then will it run the second css rule.

Example:

  • a
  • b

--

var li = $$('ul.container').first().down('li.b, li.a'); //returns li.b

Comments and changes to this ticket

  • Nick Stakenburg

    Nick Stakenburg August 3rd, 2008 @ 03:40 AM

    li.b is what you've asked for. It's the first items that matches your selector, down works like that. The first rule doesn't have to match anything for the second one to return an element. Using 1.6.0.2:

    $(document.body).down('.doesntexist, .exists'); //--> .exists
    
  • dave mankoff

    dave mankoff August 3rd, 2008 @ 06:40 AM

    But li.a matches my selector as well, and comes before li.b in the document. I would expect Element.down() to return the first item in the document.

  • Nick Stakenburg

    Nick Stakenburg August 3rd, 2008 @ 12:04 PM

    Down returns the first item matching your selector, not the first item in the DOM.

  • Nick Stakenburg

    Nick Stakenburg August 3rd, 2008 @ 03:08 PM

    You are right. I'm thinking about this knowing that .select is used internally.

    It should work different, taking the entire cssRule into account. The API mentions this:

    If cssRule is defined, Element.down will return the first descendant that matches it.
    

    Element[up|previous|next] probably also have this issue using a comma seperated cssRule.

  • Juriy Zaytsev

    Juriy Zaytsev August 4th, 2008 @ 08:44 AM

    • → Assigned user changed from “” to “Andrew Dupont”
    • → Tag changed from “class selector” to “needs_patch needs_tests selector”
    • → Milestone changed from “” to “1.6.1”
    • → State changed from “new” to “bug”

    Yep.

    #select doesn't return elements in a document order (when given multiple selectors)

    #down just takes first element from an array that #select returns.

    I checked `document.querySelectorAll` in WebKit and it seems to return document-ordered NodeList.

    Marking as bug.

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

The Prototype JavaScript library.

Shared Ticket Bins