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

  • SEARCH
  • Home
  • 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 7725603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:58:48+00:00 2026-06-01T04:58:48+00:00

This is My HTML Dom: <input type=checkbox class=chk-act name=actionChk value=17> <input type=checkbox class=chk-act name=actionChk

  • 0

This is My HTML Dom:

<input type="checkbox" class="chk-act" name="actionChk" value="17">
<input type="checkbox" class="chk-act" name="actionChk" value="18">
<input type="checkbox" class="chk-act" name="actionChk" value="19">
<input type="checkbox" class="chk-act" name="actionChk" value="20">
<input type="checkbox" class="chk-act" name="actionChk" value="21">

And I have a jQuery script that returned a JSon response by ajax:

["18","20","21"]

The list can be as long as up to 200 members. So I am interested to find out the fastest way to checked checkboxes, that have a value in above list, when the response is returned. What is your suggestion?

  • 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-06-01T04:58:49+00:00Added an answer on June 1, 2026 at 4:58 am

    The fastest way would be to add an id identifier to your list of checkboxes. For example –

    <input type="checkbox" class="chk-act" name="actionChk" value="17" id='chk-act-17' />
    //incidentally, I hope the lack of a closing '/' was an oversight
    //when you get your JSON response, in your ajax success or done methods
    var resp = ["12", "232"],
        respLength = resp.length;
    for(var i = 0; i < respLength; i += 1){
        $('#chk-act-' + resp[i]).prop('checked', true);
        //if your are using jquery 1.7+ that is, otherwise use, 
        $('#chk-act-' + resp[i]).attr('checked', 'checked');
    }
    

    JS Perf Tests

    Comparing the two current answers, the OP’s requirement of “fastest” would be better served by going down the uglier ‘id‘ implementation.
    Js Perf

    FIddle added

    JS FIddle

    Posting code from fiddle-

    var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],
        checkboxes = $('.chk');
    
    checkboxes.each(function(i, item){
        $(this).prop('checked', false);
    });
    
    arr.forEach(function(item, i) {
        $('#chk_' + item).prop('checked', true);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this HTML code for radios: <input type='radio' name='a_27' value='Yes' id='a_27_0' /> <input
HTML <div class=box> <table id=Datatable> <thead> <tr> <th><input name=checkall type=checkbox class=checkall value=ON /></th> <th>field</th>
Given this HTML: <form id=formx> <input type=text value= /> </form> And this JavaScript: $(function()
Given this HTML: <div id=foo> <input type=button class=foo abtn_1> <input type=button class=joe bbtn_2> <input
Given this HTML: <div id=foo> <input type=button class=foo abtn_1> <input type=button class=joe bbtn_2> <input
For example: <input name=abutton type=button value=This is not a button /> I know this
Given this html: <div class=nation> <a href=library.php?type=nation&amp;id=America> <div class=nation-image> <img src=nations/America.png alt=snip /> </div>
Given this HTML: <div class=OpenIDSelector>some text</div> Why does this JQuery selector match it on
i have this html: <span class=price> $61.00 <span class=detailFreeShipping>With Free Shipping</span> </span> How to
I have this Razor Template <table> <tr> <td>@Html.RadioButtonFor(i => i.Value, 1)</td> <td>@Html.LabelFor(i => i.Value,

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.