mowgli
mowgli

Reputation: 2869

Can't get onclick $(this).addClass to work

I just can't get the clicked link to change class and show as active link

See fiddle: http://jsfiddle.net/kAW4g/

$(".navul a").on('click', function(e) {

    $(this).addClass("navhover");

});

What am I doing wrong?

Upvotes: 0

Views: 131

Answers (1)

Rory McCrossan
Rory McCrossan

Reputation: 337743

The jQuery code works, the issue is that your CSS rule is not specific enough to override the default background-color, try this:

.navul a.navhover { // <--more specific selector
    color: blue;
    background-color: #6eff97;
}

Example fiddle

Also, your fiddle was not working because you did not include jQuery in the page via the dropdown on the left.

Upvotes: 7

Related Questions