While working on a webpage, I am implementing a menu that changes its background color upon being clicked using jQuery. Currently, my focus is on refining the functionality of the menu itself. However, I've encountered an issue - once I click on a menu item and then proceed to click on another one, I want the previous color change to revert without triggering a postback. Does anyone have any suggestions on how to achieve this?
Below is the code snippet:
<form id="form1" runat="server">
<div>
<link href="Content/TreeViewCss.css" rel="stylesheet" />
<div class="tree well">
<ul>
<li style="width: 100%">
<span ><i class="icon-folder-open"></i>Parent</span>
<ul style="width: 100%">
... (remaining HTML code) ...
</ul>
</li>
<li>
<span><i class="icon-folder-open"></i>Parent2</span>
<ul>
<li>
<span><i class="icon-leaf"></i>Child</span>
</li>
</ul>
</li>
</ul>
</div>
</div>
</form>
And here's the jQuery script for changing the color:
<script>
$("span").click(function () {
$(this).css("background-color", "gray");
});
</script>
I am utilizing ASP.NET WebForms, with all necessary jQuery libraries already included.