1if ($( "#foo" ).hasClass('className')) {
2 $( "#foo" ).removeClass( 'className');
3} else {
4 $( "#foo" ).addClass( 'className');
5}
1 $('li').each(function (){
2 if($(this).hasClass("active")){
3 $(this).css("color", "red");
4 }
5 else{
6 $(this).css("color", "blue");
7 }
8 });
1/* Answer to: "jquery check if element has class starting with" */
2
3if(!$(this).is('[class*="answerbox"]')) {
4 //Finds element with no answerbox class
5} else {
6 //The element has already an answerbox class
7}