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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:44:51+00:00 2026-05-17T00:44:51+00:00

I have structure: <table style=width: 100%;> <tr> <td> <a href=# class=yy>one</a> </td> </tr> <tr>

  • 0

I have structure:

<table style="width: 100%;">
    <tr>
        <td>
            <a href="#" class="yy">one</a>
        </td>

    </tr>
    <tr>
        <td>
            <a href="#" class="xx">Two</a>
        </td>

    </tr>
    <tr>
        <td>
            <a href="#" class="xx">Three</a>
        </td>

    </tr>
</table>

CSS:

.xx {
    border: 5px solid green;    
}

.yy {
    border: 5px solid red;    
}

now on click of <a> it’s class should get changed. i.e. if it’s ‘xx’ then it should turn ‘yy’ and vice-versa, and rest of the <a> should remain as it is,
I tried something like (ref:how to change class of <a> tags in jquery)

$("a.xx").click(function() {
  $(".yy").not(this).removeClass("yy");
  $(this).toggleClass("yy");
});​

but it didnt work that way, I tried to tweak the code, but it’s not working. Can somebody help.

EDIT:
May b my question was not clear enough:
if I click on 2nd <a>/ any other <a> then it should turn red and rest of the tag should be green.i.e. if the <a>is having red color, then it should turn green and and rest of the should be in red, and vice-versa .

EDIT for more clear requirement (based on replies from sje397 ):
say I am clicking on a having class xx/yy and i.e. I click on it again it should change i.e. if xx then it should go back to yy, if u again click on it, it should go back to xx. –

  • 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-17T00:44:51+00:00Added an answer on May 17, 2026 at 12:44 am
    $("a").click(function() {
      $(this).toggleClass("yy").toggleClass("xx");
    });​
    

    EDIT (due to author’s comment)

    If you want to have only one highlighted tag (i.e. having the class ‘yy’) and all others having the class ‘xx’, you can do:

    $("a").click(function() {
      var $this = $(this); // this is just for performance
      if(!$this.hasClass('yy'))
        $('.yy').toggleClass("yy").toggleClass("xx");
      $this.toggleClass("yy").toggleClass("xx");
    });​
    

    Usually, however, you would use the ‘cascading’ property of css to simplify things. For example, rather than switching classes, just add an additional class to the selected element. Then organise your CSS so that in this more specific case, the display properties which you want for the highlight override. For example, with this CSS:

    .xx {
        border: 5px solid green;    
    }
    
    .xx.yy {
        border: 5px solid red;    
    }
    

    You just need to add and remove the ‘yy’ class and leave the ‘xx’ class alone.

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

Sidebar

Related Questions

I have a table structure: <table style=width: 100%;> <tr> <td> <a href=# class=xx>one</a> </td>
I have table with following structure: <table style= margin-top: 10px; border: 1px wheat solid;
I have the following structure <table cellspacing=0 cellpadding=0 width=100%> <tr> <td style=width:60px;> ... </td>
I have a table structure, something similar to <table style=width: 100%;> <tr> <td> <a
I have table with following structure: <table class=table-info border='1px' > <tr > <td class=view
I have some table structure: <tr class=row-2><tr> <tr class=row-3>..<tr> <tr class=row-4>..<tr> <tr class=row-5>..<tr> <tr
I have a table structure like this: <table> <tr> <td> <ul> <li class=check></li> </ul>
I have a html page that contains a structure like this: <table class=pick> <tr>
Supposed We have the Html structure like below. <table class=main-tb> <tr> <td> </td> <td
I have a DOM structure like the following: <table class=playlist> <thead> <tr> <th>TH1</th> <th

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.