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 6714907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:33:02+00:00 2026-05-26T08:33:02+00:00

Is there an immediate equivalent in javascript for the below jquery code? $(‘.checkbox’).each(function() {

  • 0

Is there an immediate equivalent in javascript for the below jquery code?

$('.checkbox').each(function() {
    if ($(this).is(':checked')) {
        //logic here
    }
});

I’m trying to run through all the checkboxes on a page with class = 'checkbox' – the client doesn’t want to use jQuery, so I need an alternative for the above.

I’m hoping I can avoid writing a long function from scratch to do this and simply use something built-in to JavaScript, but it’s looking like it’s not possible.

  • 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-26T08:33:02+00:00Added an answer on May 26, 2026 at 8:33 am

    Many older browsers don’t support querySelectorAll or getElementsByClassName, so you’d have to loop over all <input> elements in those browsers. It’s always best to check for those functions first, though.

    Secondly, you should never use $(this).is(":checked") — not even in jQuery — it’s a very slow path to take when looking for this.checked.

    This should get you going:

    var base = document,
        inps, tmp, i = 0, reg = /\bcheckbox\b/;
    
    // getElementsByClassName is the fastest method
    if (base.getElementsByClassName)
        inps = base.getElementsByClassName("checkbox");
    // Followed by querySelectorAll
    else if (base.querySelectorAll)
        inps = base.querySelectorAll(".checkbox");
    // But if neither exist, loop through all the elements and check the class
    else {
        inps = [];
        var tmp = base.getElementsByTagName("input");
        i = tmp.length;
        while (i--) {
            if (reg.test(tmp[i].className)
                inps.push(tmp[i]);
        }
    }
    
    // Finally, loop through the matched elements and apply your logic
    i = inps.length;
    while (i--) {
        var current = inps[i];
        if (current.checked) {
            // logic here
        }
    }
    

    In the example above, you can change the value of base to any element. This means that, if all these elements have a common parent or ancestor node, you can set that element as the base and it should run faster, e.g:

    var base = document.getElementById("myForm");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there anyplace in the eclipse ide that I can enter immediate code while
I have a jQuery code which works perfect on desktop browsers; $(span#checkbox_err).mouseout(function () {
What's the purpose of glNormal3f in OpenGL ES? If there is no immediate mode
I wonder if there is something like a standalone version of Visual Studio's "Immediate
Once I've created a variable in the immediate window in C# (VS2008), is there
Is there any reason for my jQuery effects not to be taking effect immediately?
Using JQuery, is there a simple way to select the text immediately after a
There are two popular closure styles in javascript. The first I call anonymous constructor
Is using an if coupled with an immediate return like in the example below
3 Matlab questions 1 - Does anyone know if there is an equivalent to

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.