So I saw this question a few moments ago on SO and it got me thinking.
Basically the OP had something along these lines
<div>a</div>
<div>b</div>
<div>c</div>
<div>d</div>
$('div').each( function() {
//do something different based on whether even or odd div
if ($(this) == ':even') {} //invalid markup I know!
else {}
});
Is there a way to tell inside the .each()
whether your current element is an odd or even instance?
There is the .filter
method of jQuery, but it always returns true when it has a single element.
I also realize you can use the nth-child selector or set this up in other ways, but I am curious about this specific case.