This function determines whether any of the matched elements are assigned the given class, returning true if the searched for class is in fact assigned to an element – regardless of whether or not that element has more than one class assigned to it. (Remember, HTML allows elements may have more than one class assigned to them – separated by a space in HTML notation.)
<div id="mydiv" class="foo bar"></div>
$( "#mydiv" ).hasClass( "foo" ); //returns true $( "#mydiv" ).hasClass( "quu" ); //returns false
In other words, no need for splitting an element’s class attribute and then looping through the strings just to see if a particular class exists any more!
Related Link: https://api.jquery.com/hasclass/