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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:17:17+00:00 2026-06-09T06:17:17+00:00

As I typed this question I noticed similar question but my approach is different.

  • 0

As I typed this question I noticed similar question but my approach is different. I did read them but not what I am trying to do, however I did get some ideas.

I have three links (anchor tags) on my page, I am using JQuery to toggle a class between the links based on the link the user clicks. The link becomes active when clicked and I added Cookies to remember the user action.

What I really want to do is set the first link or the link with, example: ID equals one; to be the default. I want the same class (activeLink) which I am using to make the links active to apply to the default. When others are click, the class is than removed and the clicked link becomes active.

That’s what I don’t know how to do.

My page is a single page.
HTML:

<ul class="yeahBaby">
<li><a id="one" href="#/">Make me default</a></li>
<li><a id="two" href="#/">Example</a></li>
<li><a id="three" href="#/">Example</a></li>
</ul>

JQUERY:

$(document).ready(function() {
    var idActive = $.cookie('cookieActive');

    if (idActive) {
        $('#'+idActive).addClass('activeLink');
    }

    $('.yeahBaby li a').click(function() {
        var id = $(this).attr('id');

        $(".yeahBaby li a").removeClass("activeLink");
        $(this).addClass("activeLink");
        $.cookie('cookieActive', id); //Save anchor id as cookie
        $.cookie('cookieActive', id, { expires: 10000}); 
    });
});

CSS:

<style type="text/css">
.activeClass{
color: #999;
}
</style>

Thanks everyone!!

  • 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-09T06:17:19+00:00Added an answer on June 9, 2026 at 6:17 am

    Set the link with id="one" as default in your HTML.

    <ul class="yeahBaby">
        <li><a id="one" href="#/">Make me default</a></li>
        <li><a id="two" href="#/">Example</a></li>
        <li><a id="three" href="#/">Example</a></li>
    </ul>​​​
    

    Then in jQuery:

    // Upon loading the page set default .activeLink
    $(window).load(function() {
        // If cookie exists
        if( $.cookie('active') !== null ) {
            // Add .activeLink to last the class in cookie
            $.cookie('active').addClass('activeLink');
        } else {
            // Else set on default
            $('#one').addClass('activeLink');
        }
    });
    
    // Bind click event to each anchor in your list
    $('.yeahBaby li a').bind('click', function(e) {
        // Remove .activeLink class from current active link
        $('.activeLink').removeClass('activeLink');
        // Add .activeLink to the link just clicked
        $(this).addClass('activeLink');
        // Create cookie
        $.cookie('active', $(this));
        return false;
    });​
    

    See it in action here: JSFiddle

    — Update —

    See above for addition cookies using the jQuery $.cookie plugin.

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

Sidebar

Related Questions

I noticed some similar questions about this problem when I typed the title, but
Referring on this question , I have a similar -but not the same- problem..
I have seen many answers for this type of question but its not related
I know this type of question has been asked and answered before but I
This question is similar in spirit to : https://stackoverflow.com/questions/492178/links-between-personality-types-and-language-technology-preferences But it is based specifically
I noticed there are similar questions but I have tried the proposed solutions and
So, this may be a really stupid question, but I'm obviously missing something here.
Upon invsetigating 'mu is too short's answer to this question , I noticed that
I am not sure if there is already a nomenclature for this, but for
This question arose out of something strange that I noticed after investigating this question

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.