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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:58:57+00:00 2026-06-07T18:58:57+00:00

I have 2 push buttons, I am trying to state that if 1 button

  • 0

I have 2 push buttons, I am trying to state that if “1” button is on, turn off the “2” button, else if the “2” button is on, then turn off the “1” button.

But at the moment what is happening is that if I turn on the “2” button, and then turn on the “1” button, then this works fines as “1” button turns on and “2” button turns off. But if I then try and turn “2” button on again, it doesn’t turn it on, it remains off and button “1” remains on. Does anyone know why this is happening?

Below is code:

function btnclick(btn)
{

$(btn).toggleClass("answerBtnsOff");
$(btn).toggleClass("answerBtnsOn");

    if ($("#answer1").hasClass('answerBtnsOn')) {
        $("#answer2").removeClass('answerBtnsOn').addClass('answerBtnsOff');
    }

    else if ($("#answer2").hasClass('answerBtnsOn')) {
        $("#answer1").removeClass('answerBtnsOn').addClass('answerBtnsOff');
    }

    return false;
}

below is html for both 1 and 2 buttons:

1 button:

<input class="answerBtns answers answerBtnsOff"   id="answer1"  type="button"   value="1"   onclick="btnclick(this);"/>

2 Button:

<input class="answerBtns answers answerBtnsOff"    id="answer2"         type="button"   value="2"       onclick="btnclick(this);"/>
  • 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-07T18:58:59+00:00Added an answer on June 7, 2026 at 6:58 pm

    You’re not checking which button is being clicked.

    Something like this should work:

    function btnclick(btn)
    {
        var $btn = $(btn);
        var id = btn.id;
        var $otherBtn = id === "answer1" ? $("#answer2") : $("#answer1");
    
        $btn.toggleClass("answerBtnsOff");
        $btn.toggleClass("answerBtnsOn");
    
        if (btn.hasClass('answerBtnsOn') ) {
            $otherBtn.removeClass('answerBtnsOn').addClass('answerBtnsOff');
        }
    
        else if (btn.hasClass('answerBtnsOff')) {
            $otherBtn.removeClass('answerBtnsOn').addClass('answerBtnsOff');
        }
    
        return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a button that plays a sound. When i push the button multiple
The reason I'm trying to do this, is that I have a program that
I have many buttons in Main.mxml. I'm trying to move the button functionality into
I am trying to save data to a database on a button push, but
I am trying to have some controls appear when you push a button and
Currently I have an Array that is having 9 buttons pushed to it. This
I have just heard that - push notification is possible in iPhone I need
I have a project that I want to push to a Mercurial repository on
Scratch this! I have googled my ass off looking for this. 1. Lets say
Still a newbie here, forgive me. I'm trying to make a button that will

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.