I am trying to check to see if an HTML element has a class and if so, then run a function with jQuery. My code only works if an element doesn't have multiple classes. I believe I need to use the .hasClass() method, but I couldn't figure it out.
var pageClass = $("body").attr('class');
switch (pageClass) {
case ("page1"):
$('h1').html('heading1');
break;
case ("page2"):
$('h1').html('heading2');
break;
default:
$('h1').html('default');
}
fiddle: https://jsfiddle.net/9o70dbzz/2/
bodyhad all 3 classes? would you only want the first, or last, or append all together?