Opened 13 years ago
Closed 10 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 13 years ago by
comment:2 Changed 13 years ago by
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 13 years ago by
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 13 years ago by
Milestone: | → future |
---|
comment:5 Changed 11 years ago by
Component: | General → Query |
---|---|
Owner: | changed from anonymous to alex |
comment:7 Changed 10 years ago by
Cc: | [email protected]… alex removed |
---|---|
Owner: | changed from dylan to kriszyp |
comment:8 Changed 10 years ago by
Owner: | changed from kriszyp to Kris Zyp |
---|
comment:9 Changed 10 years ago by
Resolution: | → wontfix |
---|---|
Status: | new → closed |
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.
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.