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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:10:57+00:00 2026-05-26T03:10:57+00:00

I have table with a check-all checkbox in the header which checks all the

  • 0

I have table with a check-all checkbox in the header which checks all the checkboxes in that column of the table:

<input class="check-all" type="checkbox" id="masterCheck" />

However, on one of my pages I would like to automatically check the check-all checkbox on page load.

To do this I’ve attempted to fire a trigger(‘click’) function like the one below:

$(document).ready(function () {
    if ($("#masterCheck").attr('checked')) {
    } else {
        $("#masterCheck").trigger('click');
    }
});

This checks the checkbox fine, but doesn’t fire my custom click event for checkboxes with the class .check-all (below):

$(function () {
    $('.check-all').click(function () {
        $(this).parents('table:eq(0)').find(':checkbox').attr('checked', this.checked);
    });
});

I’ve also tried adding a Javascript setTimeout, thinking that the custom click function wasn’t being loaded quite yet, but it still didn’t fire the custom click function after waiting 1, 2, and 3 seconds.

Upon page load, I can then un-check my pre-checked checkbox and re-check it to check all of the checkboxes in the column perfectly.

Do I have to add something special to my jQuery on the Document.ready to allow it to fire the custom click event?

***EDIT1:

Ok, I’ve attempted to add the custom click event right above the document.ready function on my page to ensure it’s loaded (as the previous custom click event is in a master .js file used in my _Layout). In addition to this, I’ve changed the class of my checkbox to correspond with my new custom click event so I don’t conflict with the one in my master .js file.

<input class="check-allx" type="checkbox" id="masterCheck" />


// Check all checkboxes when the one in a table head is checked:
    $(function () { 
        $('.check-allx').click(function () {
            $(this).parents('table:eq(0)').find(':checkbox').attr('checked', this.checked);
            alert(this);
        });
    });
// Check for unchecked masterCheck
    $(document).ready(function () {
        if ($("#masterCheck").attr('checked')) {
        } else {
            //$("#masterCheck").trigger('click');
            $("#masterCheck").click();
        }
    });

This seems to throw my alert within the custom click event which is progress, but to no avail do all my checkboxes check like they should. Note: I’ve also changed the trigger(‘click’) to a .click(), which both do the same thing in my situation.

  • 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-26T03:10:58+00:00Added an answer on May 26, 2026 at 3:10 am

    Update: This only applies to jQuery 1.8 and below. This was fixed in jQuery 1.9.

    The problem is that manually calling click() in jQuery works differently than an actual click.

    When you actually click, first the checkbox state is changed, then your click handler is called.

    When you call click(), first the click handler is called, then the checkbox state is changed.

    So when you call click, in your click handler, this.checked is still going to be false. You can fix this by making it a change handler instead of a click handler, like this:

    $('.check-allx').change(function () {
        $(this).parents('table:eq(0)').find(':checkbox').attr('checked', this.checked);
    });
    

    See In jQuery, why does programmatically triggering 'click()' on a checkbox not immediately check it? for a fuller explanation of the difference between actual manual clicks and jquery triggered clicks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table setup like this: <table> <thead> <th> <input type=checkbox class=check-all />
I have a list of checkboxes, looking like this: <table> <tr><td><input type=checkbox /> <label>Bla</label></td></tr>
I have a table with a select all checkbox as the first header column
I have a table with checkboxes and I want to do the check all
I have a table with checkbox and text input column. The last row in
I have a trigger to check for a single column in a table, when
I have a user-defined table type. I want to check it's existence before editing
I am attempting to hide this checkbox, which is a check all checkbox in
I have a table as follows <table id=vainTbl6 class=dtable cellpadding=3 cellspacing=1 border=0> <thead> <tr><th>check</td><th>Morphosal</th><th>goat
i have a table in which every rows have a checkbox associated with the

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.