I have a jQuery object (thisClass) that contains 2 or more class names. I am trying to figure out how to return only the class name that is in a predetermined array.
Something like this:
var thisClass = $(this).attr("class");
var icons = ["glass","leaf","dog","home"];
[Use grep here to return thisClass only as a single class name that is filtered by, or contained in icons.]
Hmm, first of all,
attrmethod returns string not a jQuery object. In this case, it returns string with all CSS classes separate with space. If there is no class, it returnsundefined. So, you may want try this code: