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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:01:18+00:00 2026-05-17T02:01:18+00:00

I grabbed this snippet from another question: <script type=’text/javascript’ > $(document).ready(function () { $(div.content

  • 0

I grabbed this snippet from another question:

<script type='text/javascript' >
$(document).ready(function () {
 $("div.content ul li a")
 .mouseover(function () {
  var t = $(this);
  if (!t.hasClass("clicked")) {  // very easy to check if element has a set of styles
   t.addClass('mouseover');
  }
 })
 .mouseout(function () {  // attach event here instead of inside mouse over
  $(this).removeClass('mouseover');
 });

 $("div.content ul li a").click(function () {
  var t = $(this);
  t.toggleClass("clicked");
  if (t.hasClass("clicked")) {
   t.removeClass('mouseover');
  } else {
   t.addClass('mouseover');
  }
 });
});
</script>

The last thing I wanted is to restore the tabs normal css when another tab is clicked.
For example, the tab’s bgcolors are white when I click tab1 it becomes black when I go into Tab2..Tab1 goes white and Tab2 goes black

<ul> 
 <li>
  <a href="#Tab1">Tab 1</a>
 </li>
 <li>
  <a href="#Tab2">Tab 2</a>
 </li>
</ul> 

let’s say here’s the CSS part

ul li a {background-color: white;}
ul li a.mouseover {background-color: black;}
ul li a.mouseout {background-olor: white;}
ul li a.clicked {background-color: black;}
  • 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-17T02:01:19+00:00Added an answer on May 17, 2026 at 2:01 am

    You can actually greatly simplify your Javascript for this. This should achieve your desired effect.

    <script type="text/javascript">
        $(document).ready(function() {
            $("div.content ul li a")
             .mouseover(function() {
                 $(this).addClass('mouseover');
             })
             .mouseout(function() {
                 $(this).removeClass('mouseover');
             });
    
            $("div.content ul li a").click(function(e) {
                e.preventDefault(); //prevent the link from actually navigating somewhere
                $(this).toggleClass("clicked");
                $("div.content ul li a").not(this).removeClass("clicked"); //remove the clicked class from all other elements
            });
        });
    </script>
    

    The Javascript here will do the following:

    • Add the “mouseover” class when you hover a link
    • Remove the “mouseover” class when you no longer hover a link
    • When you click a link, it will toggle the “clicked” class and remove it from any other link that may have had the class – this will restore your other tabs to their “normal” state.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have grabbed some XML data using this piece of jQuery: $.ajax({ type: POST,
I have a JavaScript variable I grabbed from a form field and I am
Grabbed this from a sample: protected override ObjectContext CreateDataSource() { NorthwindContext nw = new
I grabbed this compact news reader from here Below is the code for animating
So I have this ruby code I grabbed from wikipedia and I modified a
Grabbed the images from a similar question in WPF. Basically I want the extra
I grabbed a database of the zip codes and their langitudes/latitudes, etc from this
I grabbed an example off of this SO question , and built my own
Say I have this <div id=x data-id='1' data-prop1='peace' data-prop2='out'>Text</div> in jQuery i can get
Right now I successfully grabbed the full element from an HTML page with this:

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.