Skip to content

Instantly share code, notes, and snippets.

@b-abctech
Created December 17, 2013 02:19
Show Gist options
  • Save b-abctech/7998889 to your computer and use it in GitHub Desktop.
Save b-abctech/7998889 to your computer and use it in GitHub Desktop.
detect click event on menu to add or remove class from the elements
<!-- 1. first create the menu list -->
<ul class="my-menu">
<li data-id="id-1" class="menu current">
<a href="#">hello world 1</a>
</li>
<li data-id="id-2" class="menu">
<a href="#">hello world 2</a>
</li>
<li data-id="id-3" class="menu">
<a href="#">hello world 3</a>
</li>
</ul>
<!-- 2. detect click event with jquery-->
$('.my-menu li').on('click', function(){
$('.my-menu li.current').removeClass('current');
$(this).addClass('current');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment