You can also target elements based on their positions using <code>:odd</code> or <code>:even</code> selectors.
Note that jQuery is zero-indexed which means the first element in a selection has a position of 0. This can be a little confusing as, counter-intuitively, <code>:odd</code> selects the second element (position 1), fourth element (position 3), and so on.
Here's how you would target all the odd elements with class <code>target</code> and give them classes:
Try selecting all the even <code>target</code> elements and giving them the classes of <code>animated</code> and <code>shake</code>. Remember that <strong>even</strong> refers to the position of elements with a zero-based system in mind.
testString: assert($('.target:even').hasClass('animated') && $('.target:even').hasClass('shake'), 'All of the <code>target</code> elements that jQuery considers to be even should shake.');
- text: You should use the <code>:even</code> selector to modify these elements.
testString: assert(code.match(/\:even/g), 'You should use the <code>:even</code> selector to modify these elements.');
testString: assert(code.match(/\$\(".target:even"\)/g) || code.match(/\$\('.target:even'\)/g) || code.match(/\$\(".target"\).filter\(":even"\)/g) || code.match(/\$\('.target'\).filter\(':even'\)/g), 'Only use jQuery to add these classes to the element.');