Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7012759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:17:50+00:00 2026-05-27T22:17:50+00:00

I have a function where I am iterating over each .marker , creating a

  • 0

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

            };
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:17:51+00:00Added an answer on May 27, 2026 at 10:17 pm

    inArray checks for a single value in an array. Since the value of the array reference markerClasses isn’t in checkBoxClasses, it will always return -1.

    It’s unclear what you want to do. If you want to know if any of the markerClasses entries is in checkBoxClasses, you’ll need to loop them and check them individually, breaking on the first match. If you want to check if they’re all in checkBoxClasses, 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:

    var markerClasses = $(this).attr('class').split(' ');
    var found = false;
    $.each(markerClasses, function(index, value) {
        if ($.inArray(value, checkBoxClasses) !== -1) {
            found = true;
            return false;
        }
    }
    if (found) {
        // At least one of the element's classes was in `checkBoxClasses`
    }
    

    To see if all of the element’s classes are in checkBoxClasses:

    var markerClasses = $(this).attr('class').split(' ');
    var allFound = true;
    $.each(markerClasses, function(index, value) {
        if ($.inArray(value, checkBoxClasses) === -1) {
            allFound = false;
            return false;
        }
    }
    if (allFound) {
        // *All* of the element's classes was in `checkBoxClasses`
        // (Including the case where the element didn't have any.)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that looks something like this: //iteration over scales foreach ($surveyScales
I am writing a PHP function that will need to loop over an array
I have an each() function that iterates across a number of tr elements, in
So if I am iterating using a foreach loop and I have a function
I have function getCartItems in cart.js and I want to call that function in
So I have function that formats a date to coerce to given enum DateType{CURRENT,
In my Java code I have function that gets file from the client in
I have a function that gives me the following warning: [DCC Warning] filename.pas(6939): W1035
I have a function in Ruby: def find_item(keyword) potential = [] $items.each do |item|
I have a class called Tasks that needs to store methods from other classes,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.