What am I doing wrong on the first example? It’s not targetting the span and applying the background color. But the second example works great
1st.
if($(".done").length > 0) {
$(this).css("background","red");
}
2nd.
if($(".done").length > 0) {
$(".done").css("background","red");
}
The
thisvalue is not affected by merely running a selector through jQuery. In fact, you can’t change thethisvalue at all within the confines of a particular function.You could try this:
Best to cache the
$(".done")thing of course. In this case, if that’s really all the code that’s there, there’s no reason to do the test on the length anyway.