Question about comma separated selector...
Greetings,
Karl Swedberg suggested I pass on an inquiry I made on the jquery-en
group to this one... The original inquiry was:
----
I have a general inquiry for the core dev guys... I noticed today
while running a selector that comma separated selectors build their
results by order of the selector and not by order they appear within
the originating DOM. What I mean is, if I am running a selector that
has say two different classes and I want nodes for both (ie.
div.classOne and div.classTwo) I might run $
(start).find('div.classOne, div.classTwo). My expectation when I did
this was that returned nodes would come in order of their appearance
in the DOM, but instead the children matching div.classOne are found,
and then the children for div.classTwo are found afterwards, even
though they might appear in an order like this for example:
[div.classOne, div.classTwo, div.classOne, div.classOne,
div.classTwo]. What is the rationale behind running these selectors
this way? Is this something that could be altered with a different
syntax via a plugin or something like that? The only reason I even
noticed this is because I ran the results through $.each() and needed
to deal with the nodes in their appearance. I wound up figuring out
a
work around in the end for my particular situation, but this struck
me
as worth inquiring about.
----
In the followup to the conversation I was wondering if anyone could
explain the rationale behind how this functions? I am assuming it's
performance related, am I correct? I started to look around to figure
out what would need to be changed to produce results ordered by dom
appearance, but before I went too further I thought I would seek some
background/explanation on the current implementation and if a result
set ordered by dom appearance had ever been tried before? Is it
possible to modify find() to return results by DOM order? When I
looked at the source this morning it seemed that when a comma
separated selector is handled it's copped up by the commas and then
passed through a while loop that does one after another and glues the
new results to the end. It also struck me that this would likely
return multiple nodes for a node X if node X met more then one of the
comma separated criteria - is this the case?
I've been musing over ideas in my head all morning on this one, but I
figure before I toss them out and potentially embarrass myself on the
dev list I'd inquire to see if anyone else had run into this and
worked with it before?
Thanks in advance for any feedback.
Pax,
- Stan