you would imagine this would be easy to implement, but oh well..
anyway, I have an element to which classes are added or removed based of interaction on the site.
<You have to check if class
attribute:
.
<div id="mydiv" class=""> // with class attribute but no class
<div id="mydiv"> // even without class attribute so no class
attr = $("#mydiv").attr("class")
hasClass = (attr == undefined || attr.replace(/\s+/, '') == "" )
You can do one thing take all class from the element then count the classes , try following code :-
var myClass = $("#mydiv").attr("class");
var myClassArray;
var myClassCount;
if (myClass != "")
{
myClassArray = myClass.split(" ");
myClassCount = myClassArray.length();
}
else
{
myClassCount = 0;
}
console.log(myClassCount); // Number of class attached to that element
It may help you.