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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:09:55+00:00 2026-06-01T21:09:55+00:00

I have many buttons in one form. I made one script for a few

  • 0

I have many buttons in one form. I made one script for a few particular buttons and now my other buttons are not working correctly.

Is it possible to make my button script unique for only the designated butons avoiding conflict with other buttons? It appears “input[type=’button’]” applies to all buttons in the form when I only want it to apply to a few in the script.

Here is the script I wish to modify to only work for a few particular buttons:

$(document).ready(function(){
   $(function() {
      var $buttons = $("input[type='button']");
      $buttons.click(function() {

      $(this).parent().siblings('.bx, #bxGender .gender').css({'background':'#2F2F2F','color':'#fff'});
    $buttons.not(this).removeClass('button-toggle-on');
    $(this).toggleClass('button-toggle-on').attr('style','');

    var varval = '';
    if ($(this).hasClass('button-toggle-on')) {
        varval = $(this).hasClass('gnF') ? 'Female' : 'Male';
        $(this).siblings('input[type="button"]').css('background-position','0 -180px');
    }
    else {
          $(this).siblings('input[type="button"]').attr('style','');
       $(this).parent().siblings('.bx').attr('style','');
    }
    $("#gender").val(varval);
 });});
 });



 <input type="button" class="gnM" >
 <input type="button" class="gnF">
 <input class="req-string gender" id="gender" name="gender">
  • 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-01T21:09:56+00:00Added an answer on June 1, 2026 at 9:09 pm

    Like this? Here’s an example of using classes to only affect certain elements.

    $(document).ready(function(){
        $(function() {
            $(".special-button").click(function() {
    
                $(this).parent().siblings('.bx, #bxGender.gender').css({'background':'#2F2F2F','color':'#fff'});
                $(this).siblings('.special-button').removeClass('button-toggle-on');
                $(this).toggleClass('button-toggle-on').attr('style','');
    
                var varval = '';
                if ($(this).hasClass('button-toggle-on')) {
                    varval = $(this).hasClass('gnF') ? 'Female' : 'Male';
                    $(this).siblings('.special-button').css('background-position','0 -180px');
                }
                else {
                    $(this).siblings('.special-button').attr('style','');
                    $(this).parent().siblings('.bx').attr('style','');
                }
                $("#gender").val(varval);
            });
        });
    });
    
     <input type="button" class="gnM special-button" >
     <input type="button" class="gnF special-button">
     <input class="req-string gender" id="gender" name="gender">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have many buttons and labels on my c# form. I have a button
I have WPF Form which has many buttons with the same code. Appearance of
I have a page using Paypal Payments Standard with buy one now buttons on
A small - little question. I have seen many application having buttons like following.
I have a main swf which has sound on/off buttons. It has many SWF's
When I have many controls on a Form (i.e. Label, Button etc) that do
I have a complex form that has a static section and one that can
I have container did and there are many divs inside that div. In one
I have a simple form with one input field. It works fine when I
I have an application with one main form. In the form I have one

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.