This project is archived and is in readonly mode.

#1083 ✓wontfix

Slick returns wrong results on an ID selector when there are multiple elements with the same ID

Reported by mattcoz | November 11th, 2010 @ 07:50 PM

When there are multiple elements with the same ID(yeah i know, there shouldn't be), Slick only returns the first element. This causes an additional problem when the context is an element and there exists an element with that ID outside of the element's context.

Here is a fiddle that shows the problem and then shows the native QSA behavior, which I think should be the correct behavior.

Basically this is because Slick is relying solely upon getElementById.

Comments and changes to this ticket

  • Fábio M. Costa

    Fábio M. Costa November 11th, 2010 @ 09:27 PM

    • State changed from “new” to “wontfix”
    • Assigned user set to “Fábio M. Costa”

    Hi mattcoz,

    If you have 2+ elements with the same id you dont have a valid document and a html validation will detect that.

    We, as framework developers, do our best to solve these kind of "developer mistakes", but this will create an unnecessary overhead.

    I can't rely on the existence of the "all" (which will grab all the elements with passed name OR id) property since it's not a standard, and QSA is a lot slower than GEBID.

    Thanks for your help.

  • mattcoz

    mattcoz November 11th, 2010 @ 11:31 PM

    • Assigned user cleared.

    Yeah, I normally make sure that's the case, but I ran into the issue when dynamically loading some content. I was trying to find this second element, do something with the content, then dispose of the element to keep the page valid. My problem was that I could not find that second element using getElement.

    These two calls both return null instead of the element. Is this the intended behavior?

    I ended working around it by calling querySelector directly if it's available, putting the content in a document fragment and calling GEBID if it's IE7 or lower, or falling back to GEBTN and finding it by brute force.

  • Fábio M. Costa

    Fábio M. Costa November 12th, 2010 @ 12:51 AM

    • Assigned user set to “Fábio M. Costa”


    As i said, the fix is not worth the speed decrease we will get with it.
    Your document is invalid and should be fixed.

    Thanks again, i really appreciate your help.

Create your profile

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

Shared Ticket Bins