using jQuery $(this).addClass not working, simple code not working

You didn’t ever close your <a>, but it’s working for me otherwise.

http://jsfiddle.net/L3nyE/

<ul>
    <li><a href="#">List Item 1</a></li>
    <li><a href="#">List Item 2</a></li>
    <li><a href="#">List Item 3</a></li>
    <li><a href="#">List Item 4</a></li>                        
</ul>

CSS:

.on { background-color:red; }

jQuery:

$('a').click(function(){    
      //alert('on'); WORKING
      $(this).addClass('on');
});

Leave a Comment