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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:12:13+00:00 2026-05-24T17:12:13+00:00

I have a table that lists locations and then allows a user to select

  • 0

I have a table that lists locations and then allows a user to select 1 or more permissions for that location. I have the following code working that I can select the top row check-box and you can check all the boxes in that column. I’m looking for tips to optimize what I’m doing. You click on the “.all###” check-box and all the ones with a class of “.XXX” get checked. How can I optimize my jquery? I’m still learning and although I got it to work im sure its not the best route. Any help would be appreciated.

This is my part of my HTML code

        <table>
    <colgroup></colgroup>

    <colgroup></colgroup>

    <colgroup></colgroup>

    <colgroup span="5"></colgroup>

    <thead>
        <tr>
            <th class="locationCode">Location Code</th>

            <th class="locationName">Name</th>

            <th class="locationAddress">Address</th>

            <th class="selectOption">Admin</th>

            <th class="selectOption">Remote</th>

            <th class="selectOption">Support</th>

            <th class="selectOption">Misc</th>

            <th class="selectOption">Logging</th>
        </tr>
    </thead>

    <tfoot>
        <tr>
            <td></td>
        </tr>
    </tfoot>

    <tbody>
        <tr>
            <th colspan="3" class="grayBackground"></th>

            <td class="center"><input type="checkbox" class="allAdmin admin"></td>

            <td class="center"><input type="checkbox" class="allRemote remote"></td>

            <td class="center"><input type="checkbox" class="allSupport support"></td>

            <td class="center"><input type="checkbox" class="allMisc misc"></td>

            <td class="center"><input type="checkbox" class="allLogging logging"></td>
        </tr>

        <tr>
            <td>VST</td>

            <td>Demo #1</td>

            <td>1 Street, City State</td>

            <td class="center"><input type="checkbox" class="admin"></td>

            <td class="center"><input type="checkbox" class="remote"></td>

            <td class="center"><input type="checkbox" class="support"></td>

            <td class="center"><input type="checkbox" class="misc"></td>

            <td class="center"><input type="checkbox" class="logging"></td>
        </tr>

and my jQuery

                $(function() {
                $(".allAdmin").change(function() {
                    if ($(this).prop("checked")) {
                        $(".admin").prop("checked", true);
                        return;
                    }
                    $(".admin").prop("checked", false);
                });
                $(".allRemote").change(function() {
                    if ($(this).prop("checked")) {
                        $(".remote").prop("checked", true);
                        return;
                    }
                    $(".remote").prop("checked", false);
                });
                $(".allSupport").change(function() {
                    if ($(this).prop("checked")) {
                        $(".support").prop("checked", true);
                        return;
                    }
                    $(".support").prop("checked", false);
                });
                $(".allMisc").change(function() {
                    if ($(this).prop("checked")) {
                        $(".misc").prop("checked", true);
                        return;
                    }
                    $(".misc").prop("checked", false);
                });
                $(".allLogging").change(function() {
                    if ($(this).prop("checked")) {
                        $(".logging").prop("checked", true);
                        return;
                    }
                    $(".logging").prop("checked", false);
                });
            });
  • 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-24T17:12:14+00:00Added an answer on May 24, 2026 at 5:12 pm

    This might be a bit of an overkill optimization, but this code should work:

    $(function() {
      $('.allAdmin, .allRemote, .allSupport, .allMisc, .allLogging').change(function() {
        $('.' + $(this).attr('class').split(' ')[0].substring(3).toLowerCase()).prop('checked', $(this).prop('checked'));
      });
    });
    

    If your elements have only one class (nothing like <div class="allAdmin anotherClass">), you can use this slightly shorter version:

    $(function() {
      $('.allAdmin, .allRemote, .allSupport, .allMisc, .allLogging').change(function() {
        $('.' + $(this).attr('class').substring(3).toLowerCase()).prop('checked', $(this).prop('checked'));
      });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a script that appends some rows to a table. One of the
I have a table in MySQL that looks like this: studentID subjectID anotherID anotherID2
I have a page that lists poem titles, average scores and lists the judges
I have a project that adds elements to an AutoCad drawing. I noticed that
I have a new web app that is packaged as a WAR as part
I have a sql server query question. I have a table like below. Giving
I have an unknown number of unordered lists and I want to display them
I have an application that uses a nested set model class to organise my
I have a list () in a table cell which elements contain a label
If all tables I want to delete from have the column gamer_id can i

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.