You can use the not selector attribute. This works not only for classes, but also for any attribute
if($('#elemid[class!="myclass"]').length) { $('#elemid').addClass('otherClass'); }
Of course, as mentioned earlier, if you want to add the class in which you are checking, just add it. There is no harm.
source share