Opened 12 years ago

Closed 9 years ago

#6364 closed defect (wontfix)

[Element].querySelectorAll Does Not Work As You Expect It

Reported by: guest Owned by: Kris Zyp
Priority: high Milestone: future
Component: Query Version: 1.1.0
Keywords: Cc:
Blocked By: Blocking:

Description

In a follow-up to bug #5832: The querySelectorAll method doesn't behave as you expect it to when rooted against a DOM Element, observe the following example:

<div><p id="foo"><span></span></p></div>
<script src="http://o.aolcdn.com/dojo/1.1.0/dojo/dojo.xd.js"></script>
<script>
var foo = document.getElementById("foo");
alert( dojo.query('div span', foo).length ); // should return nothing
alert( foo.querySelectorAll('div span').length ); // will return the SPAN
</script>

You can view the demo here: http://ejohn.org/files/bugs/qsa-root/dojo.html

Note: The demo doesn't have any problems in Safari 3.1 because querySelectorAll is currently disabled by [13142] (but it will have problems in a future release of Safari - and in Internet Explorer 8b1).

I, personally, feel that this is a complete mistake in the specification and implementations of querySelectorAll - and should be rectified at the specification level. If you feel similarly please voice your concerns to the Web API Working Group, otherwise here's the bug for your future reference.

Change History (9)

comment:1 Changed 12 years ago by guest

Just to clarify: The correct result is currently returned in IE 8b1 because IE 8b1 doesn't implement Element.querySelectorAll (thus, Dojo ignores it). Assumedly, however, when it does try to implement it it will do it in a way that matches the current specification.

comment:2 Changed 12 years ago by alex

Agreed. This is a spec bug, as is the inability to specify rootedness (although Maciej's ":root" proposal seems to fix that for me)

comment:3 Changed 12 years ago by guest

Yeah, I'm cool with that :root recommendation as well. Alright, I'm going to keep pushing this ahead and bring it up on the mailing list.

comment:4 Changed 11 years ago by dylan

Milestone: future

comment:5 Changed 10 years ago by bill

Component: GeneralQuery
Owner: changed from anonymous to alex

comment:6 Changed 9 years ago by Chris Mitchell

Owner: changed from alex to dylan

please review/triage

comment:7 Changed 9 years ago by dylan

Cc: jresig@… alex removed
Owner: changed from dylan to kriszyp

comment:8 Changed 9 years ago by bill

Owner: changed from kriszyp to Kris Zyp

comment:9 Changed 9 years ago by Kris Zyp

Resolution: wontfix
Status: newclosed

Yep, most agree this was a spec bug, but the ship has sailed. Dojo corrects for this bug (and so do just about every other JS library). Also, I think :scope is actually the most current recommendation for rooting.

Note: See TracTickets for help on using tickets.