I am currently working on creating a dynamic menu where I need to alter the CSS of an li element when it is clicked, while keeping the CSS of the other li elements unchanged.
Here is my menu structure:
<ul id="menu">
<li><a href="#">Parent 1</a> </li>
<li><a href="#">item 1</a></li>
<li><a href="#">non-link item</a></li>
<li><a href="#">Parent 2</a> </li>
</ul>
Here is the jQuery code I am using to apply CSS to the clicked element:
$("#menu li a").click(function() {
$(this).parent().addClass('selected');
});
However, I am currently facing an issue where I am unable to remove the added CSS from elements that are not selected. Is there a solution to this problem?