Add a class to the parent li using jquery -


i add "active" class li when clicked. "active" class should present when click on sub-page of li.

for example:

<ul class="primarynav">     <li id="first">         <a href="#" id="link1" class="">link1</a>         <ul class="megamenu" id="">             <li class="column"><h4 class="special"><a href="#">sub-link</a</h4></li>         </ul>     </li>     <li id="second">link2</li>     <li id="third"><a href="#" id="link3" class="">link3</a>         <ul class="megamenu" id="">             <li class="column"><h4 class="special"><a href="#">sub-link3</a></h4></li>         </ul>     </li> </ul> 

perhaps this

$('.primarynav a').click(function() {     // remove other links 'active' class     $('.primarynav a').removeclass('active');     // set new 'active' link     $(this).addclass('active'); }); 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -