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

  • Home
  • SEARCH
  • 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 8939473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:49:57+00:00 2026-06-15T10:49:57+00:00

I have written jquery as following <script type=text/javascript> var jq = $.noConflict(); jq(document).ready(function(){ jq(a.tag-link).click(function(){

  • 0

I have written jquery as following

   <script type="text/javascript">
     var jq = $.noConflict();
     jq(document).ready(function(){
     jq("a.tag-link").click(function(){
     jq(".selected").removeClass("selected");
     jq(this).addClass("selected");
    });
   });
  </script>

The html is something like

 <a href="home.html"class="tag-link selected" >home</a>
 <a href="about-us.html"class="tag-link" >about us</a>
 <a href="why-us.html"class="tag-link" >why-us</a>

In css a.selected{color:red;}
Now my problem is that when I click on let us say about us link, its color get changed to red only when it is clicked. But after it gets redirected to about us page.Its color changes to default one. It does not turn to red. I want that the clicked link should be red color and others should be in default color.Please please help me…

  • 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-15T10:49:59+00:00Added an answer on June 15, 2026 at 10:49 am

    Drop the entire jQuery code, just use CSS:

    a:visited {
        color:#FF0000; /* Or color:red; if you prefer not using the hex codes) */
    }
    

    The available selectors for the links are:

    a:link {}
    Defines the style for normal unvisited links.

    a:visited {}
    Defines the style for visited links.

    a:active {}
    Defines the style for active links.
    A link becomes active once you click on it.

    a:hover {}
    Defines the style for hovered links.
    A link is hovered when the mouse moves over it.

    (Source)

    Or, if you want this selection to persist when clicking a link, but not apply to all clicked links, use localStorage:

    var jq = $.noConflict();
    jq(document).ready(function(){
        if(localStorage.getItem("clickedLinkId")){ // If "clickedLinkClass" has been set.
            jq('#'+localStorage.getItem("clickedLinkId")).addClass("selected"); // add the class "Selected", to the previously clicked link.
        }
        jq("a.tag-link").click(function(){ // On click
            jq(".selected").removeClass("selected");
            jq(this).addClass("selected");
            localStorage.setItem("clickedLinkId", jq(this).attr("id")); // Save the class of the current element in the localStorage.
        });
    });
    

    HTML:

    <a href="home.html"class="tag-link selected" id="home" >home</a>
    <a href="about-us.html"class="tag-link" id="about" >about us</a>
    <a href="why-us.html"class="tag-link" id="why" >why-us</a>
    

    This should set the class of a previously clicked link, and store the clicked link in the localStorage.

    Working Sample

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

Sidebar

Related Questions

I have found the following script which is apparently written using the javascript framework
I have written a simple jQuery.ajax function which loads a user control from the
I have written a script that fires a jQuery POST to retrieve data from
I have written a form using the jQuery .post() function to post the data
Hi I am learning JQuery and I have written a small function where I
I have written the following jQuery for autorefreshing a page containing a poll (to
I am fairly new to jQuery and have written the following code to show
Possible Duplicate: jquery ajax return: undefined I have written the following code to check
I have written the following jquery code block. When a postcode is changed on
I'm a jQuery novice, I have the following jQuery written to show a div

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.