• Hi
    I use following js code to check or uncheck checkbox inputs when users click on CheckAll checkbox in my new plugin, but it doesn’t work:

    
    jQuery(document).ready( function() {
    jQuery('#element_check_all').on("click",function(e) {
        jQuery('.element_check').prop('checked', this.checked);
    });
    jQuery('.element_check:not(:first)').on("click",function(e) {
    jQuery('#element_check_all').prop('checked', false);
    });
    
    });
    

    The ID of the CheckAll checkbox is #element_check_all and all checkboxes have .element_check class. It is a simple code but I don’t know what is the problem.

Viewing 5 replies - 1 through 5 (of 5 total)
  • I have tested the code and it’s working for me. I tried with the same HTML as you have explained. All the checkboxes(including ‘check all’) have same class (element_check) and ‘check all’ checkbox has an ID #element_check_all

    Please check if there’s any console error using chrome dev tools https://developers.google.com/web/tools/chrome-devtools

    Thread Starter Mostafa Shahiri

    (@mostafadeveloper)

    @prashantvatsh Thanks for your reply. I tested it in different browsers and I checked web console. There is no error or warning. I don’t know how can I solve this problem?!

    Let’s debug it. Just after the ready function please alert something. For example alert(‘hello’);

    If this works then cut that alert code and paste inside the click function(check all).

    Also, please confirm if your JS file is enqueued properly and you can see the script in the html source(view-source).

    Any caching is there? If yes, please clear the cache.

    • This reply was modified 5 years, 9 months ago by Prashant Singh.
    • This reply was modified 5 years, 9 months ago by Prashant Singh. Reason: Additional info
    Thread Starter Mostafa Shahiri

    (@mostafadeveloper)

    @prashantvatsh I did all of your suggestions. Click event for checkbox is triggered properly and I can see ‘hello’ message per click. JS conflicts are very odd!

    Thread Starter Mostafa Shahiri

    (@mostafadeveloper)

    @prashantvatsh I considered checkboxes of WordPress posts in admin panel. The event of clicking checkbox are processed in load-scripts.php page. I think there is something in this page that makes conflict.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Check all checkbox not working’ is closed to new replies.