treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Add a class on click event

  • Hi
    I want to add a class on a click event:

    $('#nav a').click(function(){
    $(this).addClass('select');
    });

    The class 'select' is to change the look of that #nav a so that it helps the visitor to know on what page they are...
    The code work but the class is added on during the click and then it disapears. How can I do so that it stays even after the click...??
    Thanks
  • I am using wordpress for my site... is there a conflict??? I see that it works on links that I've set to a href="#" but not on links that are active...???
    Thanks
  • Try this:

    $('#nav a').click(function(){
    $(this).addClass('select');
    return false;
    });
  • Sounds like you're trying to style the navigation tab for the current page?
    If you're building the navigation dynamically, WP adds the class "current_page_item" to the appropriate li tag automatically that you can style.
  • Hi all

    I am useing this code mobile apps not add class in a:link

    Please help me

  • @vipinisvest01 I think we need more information but please start a new thread rather than resurrecting one from 2 years ago that may not apply to your specific situation.

This discussion has been closed.
All Discussions