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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:25:33+00:00 2026-06-16T04:25:33+00:00

I have some links where I’d like to basically do a class swap. When

  • 0

I have some links where I’d like to basically do a class swap. When I have it set up like so it runs all the way through:

$("#work").click(function() {
    $(".nav_middle_text").removeClass("selected");
    $(".nav_middle_text").addClass("notselected");
    $(this).removeClass("notselected");
    $(this).addClass("selected");  


    a1=1;

    $("#top_section").animate({
        height:30
    },450);
    $("#bottom_section").animate({
        height:$("#grid").outerHeight(true)
    }, 450); 
    $("#about_container").animate({
        marginTop:$("#about_container").outerHeight(true) *-1
    }, 450);   

});

But when I try to set it up this way it runs the first two add and remove classes with the specific class, but the second two using ‘this’ don’t work. Is there a reason running it this way prevents ‘this’ from working?

function nav_click() {
    $(".nav_middle_text").removeClass("selected");
    $(".nav_middle_text").addClass("notselected");
    $(this).removeClass("notselected");
    $(this).addClass("selected");          
}    



$("#work").click(function() {
    nav_click();


    a1=1;

    $("#top_section").animate({
        height:30
    },450);
    $("#bottom_section").animate({
        height:$("#grid").outerHeight(true)
    }, 450); 
    $("#about_container").animate({
        marginTop:$("#about_container").outerHeight(true) *-1
    }, 450);   
});

Thanks in advance for any help

  • 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-16T04:25:34+00:00Added an answer on June 16, 2026 at 4:25 am

    When you call the function nav_click(), this is no longer what it was inside the click handler. If you want to use the nav_click() function, then you must pass the value of this to that function. You can either do that by causing this to be set appropriately inside the function:

    nav_click.call(this);
    

    Or, you can just pass it as an ordinary argument and change nav_click() to use that argument

    nav_click(this);
    
    function nav_click(item) {
        $(".nav_middle_text").removeClass("selected");
        $(".nav_middle_text").addClass("notselected");
        $(item).removeClass("notselected");
        $(item).addClass("selected");          
    } 
    

    FYI, the value of this inside a function is determined by how that function is called. If using just a normal function call like nav_click(), then this is reset to either the window object (normal JS mode) or to undefined (JS strict mode).

    To explicitly cause this to be set to a particular value inside a function, use .apply() or .call(). See the MDN pages for a description of these methods here and here.

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

Sidebar

Related Questions

I'm have some issues adding a class to 2 navigation links on a theme.
I have a LI with some information, including some links. I would like jQuery
I have some links on my web page. When you click them Fancybox windows
I have some links at the page like: 123test.com/456 abc_test.com/sdfsd abc_test.org I have to
In my activity I have some links that when user click on it, WebView
I have some links displayed on a page. I would like to enable/disable them
i have some links in my page < a class=Qlink rel=20;5 href=javascript:void(0);>5</a> < a
I have some links and when you click on them it navigates to: foo.com/about.php#about2
On my web page i have some links like : <div id=toolbarButtons> <a href=actualites/addLink
I have some links like this: <a href=# track=yes>My Link</a> How can I detect

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.