I’m trying to add a class to a parent <li>, this is what I have been trying with no result:
function calendaractive(){
$(this).parent('li').addClass("active");
}
HTML
<li>
<a href="javascript:void(0)" onclick="calendaractive();">2009</a>
</li>
Why does this not work?
It’s better to not mix your HTML and JavaScript. It would be better to check for the click within the JavaScript itself:-
Keeping JavaScript separate from the HTML will make it easier to maintain (the same argument goes with CSS).