Checks if element has class or not

SOURCE: http://stackoverflow.com/questions/1318076/jquery-hasattr-checking-to-see-if-there-is-an-attribute-on-an-element

by Annie Lagang

HTML

<h1 id="heading" class="sample">Welcome!</h1>

JavaScript

if ($("#heading").attr("class") && $("#heading").is('[class*="sample"]'))
    alert('Look, this is showing because it\'s not undefined');
else
    alert('This would be called if it were undefined or is there but empty');