The Lodge is members-only design/dev videos and Office Hours.

Next Office Hours Session: "Implementing an SVG Icon System" Nov 30 - 6:00 PM Eastern

Add a class on click event

  • # May 5, 2011 at 7:17 pm

    I want to add a class on a click event:

    $(‘#nav a’).click(function(){

    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…??

    # May 5, 2011 at 7:21 pm

    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…???

    # May 5, 2011 at 10:03 pm

    This reply has been reported for inappropriate content.

    Try this:

    $('#nav a').click(function(){
    return false;
    # May 6, 2011 at 2:47 am

    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.

    # February 8, 2013 at 6:28 am

    Hi all

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

    Please help me

    # February 8, 2013 at 6:39 am

    @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.

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘Add a class on click event’ is closed to new replies.

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed