Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript [Solved] Combine .removeClass() AND .addClass() ?

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #150172
    Rugg
    Participant

    Hi everyone…

    is there a proper method for chaining together the .removeClass() and .addClass() using jQuery?

    The following is a snippet of code I’m referring to. the syntax feels redundant…

    $('a').click(function (e) {
    
    e.preventDefault();
    
     $('div, a').removeClass('active'); 
     $(this).addClass('active');
     $(this.hash).addClass('active'); 
    
    $('html,body').animate({
    
        scrollTop: $(this.hash).offset().top
    
    }, 500);
    
    
    });
    

    And here is a working example for a better idea…

    http://jsfiddle.net/98ShH/

    Any suggestions are welcome. thank you

Viewing 1 post (of 1 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.