code_junkie

How do I change the html element <li>'s color with a click via jQuery

Nov 14th, 2011
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. $(".clickableUL").click(function() {
  2. $(this).find("li a").addClass("active");
  3.  
  4. });
  5.  
  6. // javascript
  7. $("li>a").click(function(){
  8. $(this).parent().toggleClass("clicked");
  9. });
  10.  
  11. /* CSS */
  12. li { background: blue; }
  13. li.clicked { background: red; }
  14.  
  15. $("li").click(function(){
  16. $(this).toggleClass("clicked");
  17. });
  18.  
  19. $('a').click(function(evt) {
  20. $(evt.target).parent().css('background-color', '#fff');
  21. });
Add Comment
Please, Sign In to add comment