thiesdiggity thiesdiggity - 9 months ago 50
Javascript Question

How to write a jQuery selector with multiple :eq's in single expression?

I have a quick question. How do I write a jQuery selector expression with multiple :eq() selectors? I want to go down the DOM tree but every hope isn't uniform. Here is what I have that works:


But is the following does not work:

$('div:eq(0) div:eq(1) div:eq(5)')

Is there a more elegant way to write it without all the "find"'s?

Answer Source

I believe that you could do the following and it should return all dom elements that match:

 $('div:eq(0), div:eq(1), div:eq(5)')

You could then iterate over the results returned, hope this helps.