jquery - Add Active Navigation Class on asp.net -


i've html code:

                  <ul id="main-nav">                     <!-- accordion menu -->                     <li><a href="" class="nav-top-item   /*i want add class here*/">                         <!-- add class "no-submenu" menu items no sub menu -->                         main link </a>                         <ul>                             <li><a href="service_update.aspx">link 1</a></li>                             <li><a href="contactus.aspx">link 2</a></li>                             <li><a href="about.aspx">link 3</a></li>                         </ul>                     </li></ul> 

i want add "current" class tag --a-- when user click in main link

try this:

$('#main-nav > li > a').click(function() {     $(this).addclass('current'); }); 

if need remove class link clicked, can use following:

$('#main-nav > li > a').click(function() {     $('#main-nav a').removeclass('current');     $(this).addclass('current'); }); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -