I would like to change the tag class on click.
jsFiddle here: http://jsfiddle.net/9u8Nc/
Got this HTML code:
<ul class="tags"> <li> <a href="javascript:void(0)" class="tag">Aventure</a> <div class="user-info"> <p><b>Aventure</b> <br> + 2.300 activités</p> </div> </li> <li> <a href="javascript:void(0)" class="tag">Famille</a> <div class="user-info"> <p><b>Famille</b> <br> + 1.500 activités</p> </div> </li> <li> <a href="javascript:void(0)" class="tag">Gourmet</a> <div class="user-info"> <p><b>Gourmet</b> <br> + 500 activités</p> </div> </li> </ul>
When I click the "I want to change the style" button.
When I click on it again, I need a style back.
Try it, but it won’t work.
$('.tag').click(function() { $(this).addClass('active'); });
source share