JQuery get classes

To loop through the CSS classes of an element with JQuery, use the following code:

var myElement = $("body");
var classes = myElement.attr('class').split(/\s+/);
var match = "foo";

for(var i = 0; i < classes.length; i++){
  var className = classes[i];
  
  if(className == match){
    alert("className found");
  }
}