jQuery check if has class

with .hasClass():

if ($('.target').hasClass('selected')) { // no dot in classname
// .target elem has the class .selected
}

with .is():

if ($('.target').is('.selected')) {
// .target elem has the class .selected
}

Leave a Comment