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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:28:51+00:00 2026-06-05T05:28:51+00:00

I have a problem with the below jQuery script: $(‘span’).click(function(){ var info = $(this).attr(rel);

  • 0

I have a problem with the below jQuery script:

$('span').click(function(){
    var info = $(this).attr("rel");
    var reference = this;
    if ($(this).hasClass('listed')) {
        // alert('follow');
        $(".unlisted").addClass("unlisted-bw");
        $(".special").addClass("special-bw");
    }

    if ($(this).hasClass('special')) {
        // alert('follow');
        $(".unlisted").addClass("unlisted-bw");
        $(".listed").addClass("listed-bw");
    }   

    if ($(this).hasClass('unlisted')) {
        // alert('follow');
        $(".listed").addClass("listed-bw");
        $(".special").addClass("special-bw");
    }            
});

I want it to work in a way that if I click on one span (special, listed or unlisted), The other spans to be inactive. How can I do this with jQuery ?

I created this script but not working correctly.
http://jsfiddle.net/3nsrd/

  • 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-05T05:28:52+00:00Added an answer on June 5, 2026 at 5:28 am

    You can select all of the other spans using .siblings(). Here’s an example:

    $('span').click(function(e) {   
        $(this).removeClass('special-bw')
                .siblings("span")
                .addClass('special-bw');
    });​
    

    DEMO http://jsfiddle.net/3nsrd/4/

    This doesn’t include adding their individual hover classes, which could be done by doing a $.each on each of the siblings and using their title (or another attribute)

    $('span').click(function(e) {
        //get the name of the selected span
        selectedSpan = $(this).attr("title");
    
        //remove class of selected span -bw (i.e. special-bw);
        $(this).removeClass(selectedSpan+'-bw')
               .siblings("span").each(function(){
                //foreach of the other spans, add their name + bw
               $(this).addClass($(this).attr("title")+'-bw');
            });
    });​
    

    DEMO: http://jsfiddle.net/3nsrd/6/

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

Sidebar

Related Questions

I have the below jQuery code: $(document).ready(function () { $('#ajaxButton').click(function () { $.ajax({ url:
hey everyone, here is the site SEE BELOW I have a slight jquery problem
I have a CSS/jQuery Checkbox style script: http://jsfiddle.net/BwaCD/ The problem is, in current browsers
I have the jQuery function below which alters the CSS on hover of a
I have an issue with this jquery code below. Please give me advice or
I have a problem with getting this pop-up jquery: http://www.htmldrive.net/items/show/431/jQueryNotice-animated-notification-tooltip script to work in
I have a code like this. <html> <head> <title>Captcha With Refresh Feature</title> <script src=jquery.js
i have this jquery script that changes the color of the background instantly by
Alrighty so below I have this script doing exactly what I want; I'm using
I have recently encountered a problem in IE, using the jQuery UI datepicker script:

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.