http://api.jquery.com/each/
and I've been trying to get this function to work properly for over an hour.
Here's my function - maybe you can see what I'm doing wrong at a glance
function addStriping() {
var displayWeight = 0;
$(".optionDiv").removeClass("odd").removeClass("even").each(function(index, element) {
if (displayWeight % 2 == 0)
{
$(element).addClass("even");
} else {
$(element).addClass("odd");
}
displayWeight += 1;
});
}
What isn't working is the .addClass function. Specifically though, the error is that the Object doesn't support that method. Obviously, I'm screwing up somewhere in here.
The jQuery documentation gives the explicit example of "$(element).css("background-color","yellow") which gives the same error message.
This isn't even considering whether the iteration is top-down or not. I may have to redo the logic in the end but I still need to be able to assign classes...

New Topic/Question
Reply


MultiQuote





|