Is it possible to only select every 2nd element with the .each() function? If not, what alternatives are there?
You can use the :odd selector:
$("yourSelector:odd").each(function() {
// Will be called on every second element.
});
This might help:
$('li').each(function(index) {
if(index%2)
alert(index + ': ' + $(this).text());
});
You can use :nth-child() selector.
$("selector:nth-child(2)")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With