I want to change an element’s class using javascript/jQuery if the inner HTML of the element is 0
I tried the code below but it didn’t seem to work.
var myElement = jQuery('.thisclass');
for(var i=0; i<myElement.length; i++){
if(myElement[i].innerHTML == ' 0 '){
jQuery('.thisclass').toggleClass('.newclass');
}
}
Can someone guide me through? what am i doing wrong here? is there any simpler way to do it (all with jQuery)
jsfiddle – http://jsfiddle.net/rm5Sp/
This should do the trick: