I have a function where I am iterating over each .marker, creating a variable that contains its classes.
I also have an array named checkBoxClasses.
What I’m having a problem with is checking the classes within the variable markerClasses against the array checkBoxClasses. I want to break down the variable markerClasses and pass each individual class through the array.
Here’s the code so far:
$('.marker').each(function () {
var markerClasses = $(this).attr('class').split(' ');
if ($.inArray(markerClasses , checkBoxClasses) > -1) {
//do something
};
});
inArraychecks for a single value in an array. Since the value of the array referencemarkerClassesisn’t incheckBoxClasses, it will always return -1.It’s unclear what you want to do. If you want to know if any of the
markerClassesentries is incheckBoxClasses, you’ll need to loop them and check them individually, breaking on the first match. If you want to check if they’re all incheckBoxClasses, it’s similar but you break on the first non-match.E.g., to see if any of the element’s classes is in
checkBoxClasses:To see if all of the element’s classes are in
checkBoxClasses: