I have the following HTML structure:
<div>
<ul id="Category" class="row list-inline">
<li>
<a href="/products/Category/Cars">
Cars
</a>
</li>
<li>
<a href="/products/Category/Cars%20Racer">
Cars MVC
</a>
</li>
<li>
<a href="/products/Category/Bikes">
Bikes
</a>
</li>
<li>
<a href="/products/Category/Rollers">
Rollers
</a>
</li>
<li>
<a href="/products/Category/Scooters">
Scooters
</a>
</li>
</ul>
</div>
Clicking on the hyperlink navigates to that respective page (postback). I want to change the background color of the link which got clicked.
I have written the following script for the same:
$("#Category li").click(function () {
$("#Category li > a").each(function () {
$(this).removeClass("selectedan")
});
$(this).addClass("selectedan");
});
But with no effect. What seems to be wrong?