Created
October 3, 2019 06:01
-
-
Save sarvar/f04d9de68930411003ebad2c0dae2924 to your computer and use it in GitHub Desktop.
add class on click and remove from others
This file contains hidden or 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
| <ul> | |
| <li><a id="about-link" class="" href="#">ABOUT</a></li> | |
| <li><a id="events-link" href="#">EVENTS</a></li> | |
| <li><a id="reviews-link" href="#">REVIEWS</a></li> | |
| <li><a id="contact-link" href="#">CONTACT</a></li> | |
| </ul> |
This file contains hidden or 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
| $('ul li a').click( function(){ | |
| if ( $(this).hasClass('current') ) { | |
| $(this).removeClass('current'); | |
| } else { | |
| $('li a.current').removeClass('current'); | |
| $(this).addClass('current'); | |
| } | |
| }); |
This file contains hidden or 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
| a { | |
| transition:all 200ms; | |
| color:#333; | |
| background:#eaeaea; | |
| } | |
| .current { | |
| color:#900; | |
| background:#bbb; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment