IN the following JQuery/JS code —
$("a#go-to-videos").click(function(event){
var hello = 'hello'
event.preventDefault();
if ($(this).text().length <= 30) {
$(this).parent().parent().append($('<li>hello</li>'));
} else {
return
}
});
$("ul#odd-even li:odd").addClass("odd")
When I click to add a new item, the $("ul#odd-even li:odd").addClass("odd") does not apply to it? Why is this so and what is the best workaround for this?
It doesn’t look like the addClass is actually happening onClick. You should add
$("ul#odd-even li:odd").not('.odd').addClass("odd")inside the click function.