Ticket #6364 (new defect)

Opened 8 months ago

Last modified 5 months ago

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

Reported by: guest Owned by: anonymous
Priority: normal Milestone: future
Component: General Version: 1.1.0
Severity: normal Keywords:
Cc: jresig@…, alex

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

Changed 8 months 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.

Changed 8 months 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)

Changed 8 months 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.

Changed 5 months ago by dylan

  • milestone set to future
Note: See TracTickets for help on using tickets.