I have this snippet of code that I am using to create a filter for WordPress categories and their posts. The thing is the links for changing the filter categories need to use 2 background images for the style I am creating. Here is the code I am using for the jQuery:
So everything works fine, except, instead of applying the “on” class to the a element, I want to apply it to the li that is around the a. The original code is:
$('div#filter ul a').removeClass('on');
So, I had changed it to:
$('div#filter ul li').removeClass('on');
It is very successfully removing the “on” class from the li, but it isn’t adding back. I know this is something super simple to fix, but I just can’t figure it out. Any suggestions?
since you want to bind the click event to the li instead of the a (maybe I’m wrong in assuming this?). In the current state of your code the “on” class probably gets added to the a inside the li? That’s because the click event is binded to the a element, so “this” will point to the a element.