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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:16:02+00:00 2026-05-22T14:16:02+00:00

I have a table of checkboxes. When I click a div with text Select

  • 0

I have a table of checkboxes. When I click a div with text “Select All” it should select all chekboxes and the div’s text needs to change to “Unselect all” irrespective of any check box is checked or not and vice versa.

I have written the following, it’s working fine, is there any better way to do it?

   if($(this).text() == "Select All") {
        $(this).text("Unselect All");
        $.each($(".classname"),function(i ,ll){
           $(this).attr('checked', true);
        });
    }else{
        $(this).text("Select All");
        $.each($(".classname"),function(i ,ll){
          $(this).attr('checked', false);
        });
    }

thanks.

  • 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-22T14:16:02+00:00Added an answer on May 22, 2026 at 2:16 pm

    First of all, $() is a function call so you should say var $this = $(this) if you’re going to be using $(this) a lot. Also, your $.each loops are redundant as the jQuery objects apply their changes to all the matched elements anyway so looping is not needed (i.e. the jQuery methods are set based). You’re probably better off removing the checked attribute rather than setting it to false too. Something like this would probably be better:

    var $this = $(this);
    if($this.text() == 'Select All') {
        $this.text('Unselect All');
        $('.classname').attr('checked', true);
    }
    else {
        $this.text('Select All');
        $('.classname').removeAttr('checked');
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with checkboxes and I want to do the check all
I have a table with a select all checkbox as the first header column
I have a table with multiple rows which contain form inputs (checkboxes, text, dropdowns).
I have a table of todos and on the leftmost column are normally checkboxes
I'm currently dynamically building an asp:table which contains checkboxes these checkboxes have a CheckChanged
I have a collection of checkboxes loaded from a table that are loaded in
I have table inside a div tab. The table has 40 rows in it
I have table with 3 columns A B C. I want to select *
I have a table with checkboxes in the first column. I use the jQuery
I have a form with a table that has two input boxes, a select

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.