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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:35:38+00:00 2026-06-09T03:35:38+00:00

update at the bottom There are 4 divs that are set to look like

  • 0

update at the bottom

There are 4 divs that are set to look like toggle buttons. When a button is toggled on:

-it is animated as a pressed button,

-it retrieves some content and it places that content into a box, and then

-it returns a value of 1 to an array.

(no problem.)

Problem:
When there is already one button button pressed, I don’t understand how to toggle the first button off without also turning the other one off or affecting the other buttons. How can I pass the output of one button to the others so they know who they have to turn off when they turn on?

My solution thus far has been to create 2 arrays:

var arrayValues [ a, b, c, d]; //the values of each button state: [0,0,0,0] <-all off | all on-> [1,1,1,1]
var addedValues = [a + b + c + d]; //the values of each array item added together: [0+0+0+0]= 0 <-all off | all on-> [1,1,1,1]=4

and then

if (addedValues = 0) {
console.log("cool, nothing is pressed yet. I am going to return true, but where does that return value go? How can I access it?");
return true;

} else if (addedValues > 1) {
console.log("ok I now know that at least one button has already been pressed, but how can I tell the other buttons which one was already pressed?");
}

For example if the first button is toggled on
arrayValues = [1,0,0,0]

and now the second button has been toggled on so it says
arrayValues = [1,1,0,0]

but how can I pass that information into all of the buttons? This next part is obviously flawed but it’s the only thing I could think of doing:

} else if(addedValues >= 2) {

        arrayValues[0] = arrayValues[0] - 1;
        arrayValues[1] = arrayValues[1] - 1;
        arrayValues[2] = arrayValues[2] - 1;
        arrayValues[3] = arrayValues[3] - 1;

}

so now, the only values that are not negative are the two buttons in active states… but that does nothing for because we already knew that. How can I tell the buttons which button to subtract 1 from without affecting any of the other buttons?

Update: To see the madness in context http://jsfiddle.net/Luhring/EjW7A/23/

*update: *
Just to clarify: the buttons aren’t only just toggling their appearances, they’re changing other content displayed on the page:
When you click each button the content changes. each button has 1 original group of original content that is toggled on/off with the button. like changing the channel on a tv screen with a remote control.

so if button 1 is pressed, when button 2 is pressed button 1 must turn off (removing its’ content and animating back up to its’ original position) in order to allow button 2’s stuff to display.

shout out to @nbrooks for writing 4 lines of code that more or less did as much as I did in +100. Still not solved but his is WAY more efficient than mine (you can see his version here: http://jsfiddle.net/EjW7A/20/ ) )

  • 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-09T03:35:40+00:00Added an answer on June 9, 2026 at 3:35 am

    Updated Demo, according to new reqs: http://jsfiddle.net/EjW7A/24/

    $(function() {
        $('.plain').click(function() {
            var newClassName = $(this).is('.selected') ? '' : this.id;
            if ($(this).is('#content')) return;
            $(this).toggleClass('selected', 1000);
            $('#content').attr('class', 'plain '+newClassName);
            $('.selected').not(this).removeClass('selected');       
        });
    });​
    

    Update to your fiddle demo

    The best way to do this is just give the elements a common class, to which you can bind a click handler and a css rule. This will accomplish your function of only having one button being pressed at a time, plus the ability to turn it on/off without affecting the others.

    Javascript (jQuery):

    $(function() {
        $('.plain').click(function() {
            $(this).toggleClass('selected');
             $('.selected').not(this).removeClass('selected');       
        });
    });​
    

    HTML

    <div id="a" class="plain">
        <p>A</p>
    </div>
    

    CSS

    .plain {
        width: 200px; height: 200px; margin: 20px; text-align:center; float: left;
        font-size: 100px; color:#fff; background-color:red;
    }
    p { margin-top: 25%; margin-bottom:25%; }
    .selected { background-color: blue; }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update: See the bottom of this question for a C# workaround. Hi there, Consider
Say, there is a bar that is styled at the bottom of the viewport,
I am making a button that looks like this: <!-- Container --> <div> <!--
Important Update: See update 5 at the bottom there is no performance issue in
(Please see update at bottom) I've looked at dozens of questions and haven't been
UPDATE AT THE BOTTOM Maybe somebody could help with this... been struggling with it
Update Solution Found See Bottom of post if interested Seems simple enough and for
UPDATE: First problem solved, second one described at the bottom of this post. UPDATE2:
Update: Is there a way to achieve what I'm trying to do in an
UPDATE: I've been playing around with this more, and it seems like tmux's clear-history

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.