Following the instructions in the comments of the function below, I tried to select every member of the class ‘piece,’ divide it in half (using :even :odd selectors) and then add two different classes to them. But I’m getting an error message that that says there are 0 members of each class. Have I selected them incorrectly?
function setUpPieces() {
//select all the divs with class 'piece'
//add the 'light' class to half of them
//add the 'dark' to the other half
$('.piece:even').addClass('light');
$('.piece:odd').addClass('dark');
}
Update:
These are the instructions
The jQuery selectors :even and :odd may be useful.
An example:
$('div:even')
selects half of the divs on the page: the first one (the one at index 0) and then every second div after it (the ones at indicies 2,4,6 ...)
$('div:odd')
selects the other half.
When is the setUpPieces function running? Make sure you’re applying that after the document ready. The code you have to add the classes look correct. Here’s a Fiddle showing it in action:
http://jsfiddle.net/DeGeb/