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

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -