Grow your CSS skills. Land your dream job.

Add a class on click event

  • # May 5, 2011 at 7:17 pm

    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

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

    # May 5, 2011 at 10:03 pm

    Try this:

    $('#nav a').click(function(){
    $(this).addClass('select');
    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.

*May or may not contain any actual "CSS" or "Tricks".