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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:31:46+00:00 2026-06-04T04:31:46+00:00

I am trying to change the class of a button when a checkbox is

  • 0

I am trying to change the class of a button when a checkbox is checked but I’m having trouble getting it right. When the checkbox is selected I want to change the buttons class to buttonsshow from buttonshide.

HTML

<div class="checkbox">
    <input id="ChartstoDisplayAll" type="checkbox"     name="ctl00$MainContent$ChartstoDisplayAll" /><label for="ChartstoDisplayAll">Select All</label>
    <p class="checkbox" style="margin-left:5px;"> or select individually below </p>
    <hr class="horizline" style="width:870px;"/>
</div>

    <div id="buttons" class="buttonshide">
        <input type="image" name="ctl00$MainContent$btnGetChart"  id="MainContent_btnGetChart" title="Click here to retrieve the charts" Text="Build the  Charts" src="Styles/Images/stats.png" alt="Build the Charts" align="left" />
        <p style="font-size:.8em; font-weight:bold;">Build Charts</p>
    </div>

FYI…There is other html between these two divs. I took it out for brevity as none have an id of buttons.

Here is the javascript. (the latest way that I’ve tried)

 //this script will change the style of the "Select All" checkbox and make visible the "Build Chart" button
  $(document).ready(function () {
      $('#ChartstoDisplayAll').click(
          function () {
              $("INPUT[type='checkbox']").attr('checked', $('#ChartstoDisplayAll').is(':checked'));
              $(this).next().toggleClass("selected");
              $(this).find("buttons").toggleclass("buttonsshow");
          });
  });

​
Here is the fiddle link
http://jsfiddle.net/dinotom/h25tM/2/

Here is the completed, working script which changes the text color and shows the button when the checkbox is selected.

 //this script will change the style of the "Select All" checkbox and make visible the "Build Chart" button
  $(document).ready(function () {
      $('#ChartstoDisplayAll').change(
          function () {
              if ($('#ChartstoDisplayAll').is(':checked')) {
                  $(this).next().addClass("selected");
                  $('#buttons').addClass("buttonsshow").removeClass('buttonshide');
              } else {
                  $('#buttons').addClass("buttonshide").removeClass('buttonsshow');
                  $(this).next().removeClass("selected");
              }
          });
  });
  • 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-04T04:31:47+00:00Added an answer on June 4, 2026 at 4:31 am

    Try this:

    if ($('#ChartstoDisplayAll').is(':checked')) {
      $(this).find("buttons").addClass("buttonsshow").removeClass('buttonshide');
    } else {
      $(this).find("buttons").addClass("buttonshide").removeClass('buttonsshow');
    }
    

    Also, you should use the change event instead of click

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

Sidebar

Related Questions

I'm trying to change a Button's Click property/event when a DataTrigger is triggered but
I am trying to change the class of a element with Javascript using the
I am trying to change the property type in interface implementation class using explicit
I am trying to access/change the properties of a class' Parent through Reflection. If
All I am trying to do is to change the state of checkbox on
I'm currently trying to create a ControlTemplate for the Button class in WPF, replacing
I've been trying to learn delegates.I just created a button,label and checkbox. If I
I am trying to change cursor of a button in MFC dialog. i have
I'm trying to make this button change background when you click it and this
I am trying to click a checkbox that enables a purchase button to appear.

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.