javascript - All links with one class - how to add additional class on click? -


it possible if have more links same class, on click add aditional class active item? have tried jquery '.toggleclass()' if click on next link both links has same class

<a href="link1.html">1</a> <a href="link2.html">2</a> <a href="link3.html">3</a> 

i have tried:

$('a').click(function() {      $('a').toggleclass('active');  }); 

i don't see class in html, add example. try this:

html

<div class="menu"> <a href="link1.html">1</a> <a href="link2.html">2</a> <a href="link3.html">3</a> </div> 

jquery

$('.menu a').click(function(){ //check thru <a> elements  inside .menu     $('.menu ').removeclass("active"); // remove active class         $(this).addclass("active"); //put active in parent of <a> clicked }); 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -