Created
December 17, 2013 02:19
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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