I am looking to dynamically add a class to a DIV after clicking on an A element with the same class. Here is an example:
<ul>
<li><a href="#1" class="test1">1</a></li>
<li><a href="#2" class="test2">2</a></li>
<li><a href="#3" class="test3">3</a></li>
</ul>
<div class="test">
<div class="test1">test1</div>
<div class="test2">test2</div>
<div class="test3">test3</div>
</div>
If I click on a.test1, I want to add the class ACTIVE to both the a and div elements with the class test1. I have managed to achieve this for the A element using jQuery, but I'm not sure how to handle it for the DIV element.
jQuery(document).ready(function() {
jQuery('ul li').click(function() {
jQuery("li.active").removeClass("active");
jQuery(this).addClass('active');
});
})
Any suggestions or solutions are greatly appreciated! Thank you!