#262 ✓resolved
dave mankoff

Element.down() Does Not Always Match First Element

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

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 set to “Andrew Dupont”
    • State changed from “new” to “bug”
    • Tag changed from class, selector to needs_patch, needs_tests, selector
    • Milestone set to 1.7

    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.

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 02:26 AM

    • Tag changed from needs_patch, needs_tests, selector to missing:tests, needs_patch

    [not-tagged:"needs_tests" tagged:"missing:tests" bulk edit command]

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 02:28 AM

    • Tag changed from missing:tests, needs_patch to missing:patch, missing:tests

    [not-tagged:"needs_patch" tagged:"missing:patch" bulk edit command]

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 03:36 AM

    • Tag changed from missing:patch, missing:tests to missing:patch, needs:tests

    [not-tagged:"missing:tests" tagged:"needs:tests" bulk edit command]

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 03:37 AM

    • Tag changed from missing:patch, needs:tests to needs:patch, needs:tests

    [not-tagged:"missing:patch" tagged:"needs:patch" bulk edit command]

  • T.J. Crowder

    T.J. Crowder November 16th, 2009 @ 04:50 PM

    • Assigned user cleared.

    [responsible:none bulk edit command]

  • Tobie Langel

    Tobie Langel March 1st, 2010 @ 12:41 AM

    • Tag changed from needs:patch, needs:tests to needs:patch, needs:tests, section:dom
  • Andrew Dupont

    Andrew Dupont October 17th, 2010 @ 09:26 AM

    • State changed from “bug” to “resolved”
    • Importance changed from “” to “”

    Fixed in 1.7 because Sizzle handles this properly.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

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

Referenced by

Pages