javascript - Removing active class if clicking active link a second time? -
i came across question wanted add active link clicked menu item.
the solution add:
$("a").click(function(){ $("a").removeclass("active"); $(this).addclass("active"); });
now how can remove active class if click active link second time? i'm guessing need use toggleclass() haven't been able make work. note 1 link should have active class @ time.
here demo: http://jsfiddle.net/a6dqq/
you can do:
$('a').click(function(e){ e.preventdefault(); var $a = $(this); $a.toggleclass('active').siblings().removeclass('active'); });
Comments
Post a Comment