DevKev
DevKev

Reputation: 6304

Jquery how to set active link css color

Demo: http://jsfiddle.net/f9FDs/

How can i get the link color to change to the active link (last clicked) color specified in CSS?

// Active Menu Link
jQuery("#navbar-main li a").live('click', function () {
    jQuery("#navbar-main li a").removeClass("selected");
    jQuery(this).addClass("selected");
    return false;
});

Upvotes: 0

Views: 1783

Answers (2)

htxryan
htxryan

Reputation: 2961

"live" is deprecated. Use "on" instead.

Fiddle: http://jsfiddle.net/f9FDs/3/

jQuery("#navbar-main li a").on('click', function () {
    jQuery("#navbar-main li a").removeClass("selected");
    jQuery(this).addClass("selected");
    return false;
});

Upvotes: 6

Johan
Johan

Reputation: 35194

You are using a deprecated method which doesn't exist in the version of jQuery that you posted in the fiddle.

Switch from live() to on()

http://jsfiddle.net/f9FDs/4/

Please note that if you're using live() for dynamically generated elements, the on() eqvivalent takes 3 arguments to make use of event delegation:

jQuery("#navbar-main").on('click', 'li a', function () {

Upvotes: 5

Related Questions