PDA

View Full Version : Selector weirdness



TommyMaintz
24 Jan 2007, 2:42 AM
Hey guys,

I don't know if this is something wrong on my side or just in my brain but i have the following markup:



<div id="websites">
<div id="website-1">


...</p>
<div>...</div>
</div>
<div id="website-2">


...</p>
<div>...</div>
</div>
<div id="website-3">


...</p>
<div>...</div>
</div>
<div id="website-4">


...</p>
<div>...</div>
</div>
<div id="website-5">


...</p>
<div>...</div>
</div>
<div id="website-6">


...</p>
<div>...</div>
</div>
<div id="website-7">


...</p>
<div>...</div>
</div>
<div id="website-8">


...</p>
<div>...</div>
</div>
<div id="website-9">


...</p>
<div>...</div>
</div>
...etc


Now i want to select website 2, 5, 8.

With cssQuery i was using the following query:

'#websites > div:nth-child(3n+2)'

This one doesn't work in DomQuery.
I looked up the definition of nth-child on w3. Here it is:

The :nth-child(an+b) pseudo-class notation represents an element that has an+b-1 siblings before him...

This means that the proper selector to do this would be:

'#websites > div:nth-child(3n+2)'

With DomQuery however its all a bit strange.
When I use:

'#websites > div:nth-child(odd)'
it returns website-1, website-3, website-5....

this is correct

When i use:

'#websites > div:nth-child(even)'
it returns website-2, website-4, website-6... etc

this is correct aswell

When i use:

'#websites > div:nth-child(2)'
it returns p, p, p, p, p.... etc

while it should return website-2 (i think, this is what i dont know for sure...)

When i use:

'#websites > div:nth-child(3n+2)'

it returns nothing.

Can somebody maybe explain to me what i am doing wrong?
Or is it just strange behaviour of DomQuery.

jack.slocum
24 Jan 2007, 7:22 AM
It's not a bug, nth-child(an+b) is not supported. This was a decision I made at some point, but I am open to reconsidering. IMO It's one of those selectors that is not very useful except for css. The performance (it would be slow) and code/complexity to implement it didn't seem worth it.

As for '#websites > div:nth-child(2)', I created a test page and executed it locally and it worked as expected (1 div element). Are you running the latest DomQuery.js? I've never seen this problem in an older version either, but it makes sense to try the latest code.