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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:36:20+00:00 2026-05-31T04:36:20+00:00

I call jquery function onclick at links. For example: <a class=active href=# onClick=Animate2id(‘#box1’); >Content

  • 0

I call jquery function onclick at links. For example:

<a class="active" href="#" onClick="Animate2id('#box1');" >Content 1</a>
<a href="#" onClick="Animate2id('#box2');" >Content 2</a>
<a href="#" onClick="Animate2id('#box3');" >Content 3</a>

As you can see, first link has by default class ‘active’. I want to remove the class from first link and add to the link which is clicked.
For that purpose, I’m trying to add following line inside the Animate2id function:

$('.active').removeClass('active');
$(this).addClass('active');

It just removes the class from the link.
But this does not add the class to any of the link. How I can fix that?

Edit:
Here is complete jQuery function:

function Animate2id(id){ 
    var animSpeed=2000; 
    var $container=$("#container"); 
    if(ease){ 
        var easeType=ease;
    } else {
        var easeType="easeOutQuart"; 
    }

    $container.stop().animate({"left": -($(id).position().left)}, animSpeed, easeType);
}
  • 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-31T04:36:22+00:00Added an answer on May 31, 2026 at 4:36 am

    If you have the <a> tags in a parent element with an id, you can do this:

    $('#parent_element_of_links a').click(function(e) {
        e.preventDefault();
        $('#parent_element_of_links a').removeClass('active');
        $(this).addClass('active');
    });
    

    Working example: http://jsfiddle.net/fDZ97/

    You could also just put the code above in your Animate2id() function that you have:

    function Animate2id(id, ease) {
        var animSpeed = 2000;
        var $container = $("#container");
        if (ease) {
            var easeType = ease;
        } else {
            var easeType = "easeOutQuart";
        }
    
        $container.stop().animate({
            "left": -($(id).position().left)
        }, animSpeed, easeType);
    
        // remove "active" class from all links, add it to this one
        $('#parent_element_of_links a').removeClass('active');
        $(this).addClass('active');
    }​
    

    Update

    The this keyword wasn’t working because it was referring to the window rather than the link. So I added an extra parameter in the function and it works perfectly now, just remember to add this in the onclick (right before you define the ease variable):

    function Animate2id(id, t, ease) {
        var animSpeed = 2000;
        var $container = $("#container");
        if (ease) {
            var easeType = ease;
        } else {
            var easeType = "easeOutQuart";
        }
    
        $container.stop().animate({
            "left": $(id).position().left
        }, animSpeed, easeType);
    
        // remove "active" class from all links, add it to this one
        $('#links a').removeClass('active');
        $(t).addClass('active');
    }​
    

    Working jsFiddle Example: http://jsfiddle.net/Uqqmy/

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

Sidebar

Related Questions

I am using jQuery. I call a JavaScript function with next html: <li><span><a href=javascript:uncheckEl('tagVO-$id')>$tagname</a></span></li>
I am using jQuery and JavaScript, I need to call the jQuery function inside
I am trying to call a user defined function in jQuery: $(document).ready(function() { $('#btnSun').click(function()
I am using the $.ajax function in jquery to make a call to an
I'm trying to call a Page Method using a jQuery 'attached' event function, in
I'm trying to call a function that contains jQuery code. I want this function
I am using the below jquery code to call a ajax function in my
I use the following the jquery statements to call my php controller function, it
I would like to call a jQuery pager function (p) defined as: function p(page)
Hi in my html document I have a call to a jQuery function. The

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.