Reputation: 6304
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
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
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()
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