I have the following html structure:
<ul>
<li id = "1"><a href = "">1</a></li>
<li id = "2"><a href = "" class = "active">2</a></li>
<li id = "3"><a href = "">3</a></li>
<li id = "1"><a href = "">4</a></li>
</ul>
I would like to apply the class of “active” to the li element with id 2. I tried the following:
if(jQuery('#navigation ul li a').hasClass('active')){
jQuery(this).parent().addClass('active');
}
But it doesn’t seem to work.
Use the following: