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

c# - SelectList with Dictionary, add values to the Dictionary after it's assigned to SelectList -

how can i manage url using .htaccess in php? -

ios - I get the error Property '...' not found on object of type '...' -