Is there a way in jQuery to loop through or assign to an array all of the classes that are assigned to an element?
ex.
Here you go, just tweaked readsquare's answer to return an array of all classes:
function classList(elem){
var classList = elem.attr('class').split(/\s+/);
var classes = new Array(classList.length);
$.each( classList, function(index, item){
classes[index] = item;
});
return classes;
}
Pass a jQuery element to the function, so that a sample call will be:
var myClasses = classList($('#myElement'));