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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:58:43+00:00 2026-06-17T18:58:43+00:00

How can I target a subset of all buttons with a specific class? What

  • 0

How can I target a subset of all buttons with a specific class? What i’m trying to accomplish is, that only one button with P or S can be selected at a time. If a user clicks on a specific “P” button it removes the highlight class from every other “P” button, same with “S”.

http://jsbin.com/adopuz/1/edit

$(':button').on('click', function() {

      var typeid = $(this).attr('value');
      $(this).addClass('highlight');

      if(typeid == 'P') {
        $('.primary').val(0);

        $(':button').removeClass('highlight');

        var opts = $(this).parent().find('input').eq(0).val(1);


      }

      if(typeid == 'S') {

      $('.static').val(0);
      var optp = $(this).parent().find('input').eq(1).val(1);

      }

    });

HTML

  <div id= "US">
    This is the US
  <div id="Monday">

<input name='' value='1' class="primary" type=''>
<input name='' value='0' class="static" type=''>


<input type='button' value='P' class='P'>
<input type='button' value='S' class='S'>

  </div>

    <div id="Tuesday">

<input name='' value='1' class="primary" type=''>
<input name='' value='0' class="static" type=''>

<input type='button' value='P' class=''>
<input type='button' value='S' class=''>


  </div>

      <div id="Wednesday">

<input name='' value='1' class="primary" type=''>
<input name='' value='0' class="static" type=''>


<input type='button' value='P' class=''>
<input type='button' value='S' class=''>

  </div>
  </div>
  • 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-17T18:58:44+00:00Added an answer on June 17, 2026 at 6:58 pm

    First of all, you have a little error in your HTML: you’ve only set the ‘P’ or ‘S’ class in the first couple of buttons. The next ones have ” as class. You must set the class for the following code to work.

    Fixed that, you should first unset all the ‘highlight’ classes, and then set the one you’re interested in:

    http://jsbin.com/adopuz/8/edit

    $(':button').on('click', function() {
    
      var typeid = $(this).attr('value');
    
      if(typeid == 'P') {
        $('.primary').val(0);
    
        $(':button.P').removeClass('highlight');
        $(this).addClass('highlight');
    
        var opts = $(this).parent().find('input').eq(0).val(1);
      }
    
      if(typeid == 'S') {
        $('.static').val(0);
    
        $(':button.S').removeClass('highlight');
        $(this).addClass('highlight');
    
        var optp = $(this).parent().find('input').eq(1).val(1);
      }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a specific version of .Net that I can target that is bundled
I know in Visual Studio 2008 you can target a specific framework with your
I want to develop a program in c# that can target and application or
I'm trying to change the color of the Asterisk but I can't target the
I am developing a silverlight application where you can set sales target for specific
Can any one please tell me the difference between target and currenttarget in flex?
Edit What I'm actually asking if I can target the div my button is
I am trying to write a PowerShell script that will copy a subset of
I am wondering how I can target a specific commit SHA in Git for
I understand that css rules can target elements specified by attribute values, e.g.: input[type=text]

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.