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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:21:22+00:00 2026-05-23T06:21:22+00:00

I have a css rule like this: .foo:active { background-position: 0px -382px; } .foo

  • 0

I have a css rule like this:

.foo:active {
    background-position: 0px -382px;
}

.foo is applied to an anchor.

I have a set of several buttons displayed side by side.

I need to have a very common behaviour here:

When the user clicks on button 1, it stays active.
If the user clicks on button 2, that should be active and the orders shouldn’t.
If we click on button 3 the same thing… and so on…
So, we should only allow one active button.

Can we deal with this using javascript or should we rely on a server side language?

Perhaps javascript will do the job, since, here, we are not refreshing the page each time the user clicks on one of those buttons.

What is the logic behind this ?

Update:
I should add something to onclick event, I should allow to onclick, apply a class that places the background in a way that the element looks active. But, I’m not sure, how to deal with the part that ONLY ONE of those 9 should be active. :s

Note: should I provide more details, please, let me know.


CODE SAMPLE:

function showDetails(eid){
  $.post(baseUrl+"/index/show.details",{id:eid},function(e){

  ...

  //remove ativoFinalista class from all elements with .botoesEquipas class.
  $('.botoesEquipas').removeClass('ativoFinalista'); 

  //add the class to the clicked element
  $(this).addClass('ativoFinalista'); 

 }, 'json');
}

Css:

I have nothing defined for .botoesEquipas.

.ativoFinalista {
    background-position: 0px -130px;
}

The anchor:

<a class="botoesEquipas botaoFinalista<?php echo $e["cod_team"];?>"
 href="javascript:;" onclick="showDetails(<?php echo $e["cod_team"];?>)"><?php echo$e["name"];?></a>
  • 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-05-23T06:21:23+00:00Added an answer on May 23, 2026 at 6:21 am

    You can use jQuery, but note that a class fooactive is needed:

    $('.foo').click(function() {
        $('.foo').removeClass('fooactive'); // Remove active class from all elements of class foo
        $(this).addClass('fooactive');      // Add active class to this specific one
    });
    

    Then code CSS like:

    .foo { /* default foo style */ }
    .fooactive { /* extra styles when active */ }
    

    Edit: You bind click functions the old way. In that case, pass the element like:

    onclick="showDetails(123,this)"
    

    and

    function showDetails(eid, element){
      $('.foo').removeClass('fooactive'); 
      $(element).addClass('fooactive'); 
    }
    

    http://jsfiddle.net/eEJma/

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

Sidebar

Related Questions

I need to inline css from a stylesheet in c#. Like how this works.
I have this strange issue with css hover, on chrome and safari (on opera
Given the following CSS rule, #block1 { text-indent: -1000em; background: transparent url(../images/xxx.png) no-repeat scroll
I am working on this site, and I have a pretty large .css document.
UPDATE: It was suggested in the comments that I create a wiki for this.
I see the following usage of CSS and I add my understanding in the
Here is some normal code for sprite menu #menu li a { background:url('../layout/menu.jpg') no-repeat;
I added to every textarea, every textfield and every button a special class. I
I'm a webdeveloper with an emphasis on server-side programming. What little I've tinkered with
I've been using the in-line styles approach as recommended by GWT's UiBinder documentation .

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.