While developing a web application in Django, I wanted to find a simple way to track the user's location on the site. My solution was to change the CSS of the menu item clicked by the user.
After adding this straightforward piece of code:
<script type="text/javascript">
$(document).ready(function(){
$(".up_menu_item").click(function(){
$(this).addClass("green");
var excludeThis = $(this);
$(".up_menu_item").not(excludeThis).each(function(){
$(this).removeClass("green");
});
});
});
</script>
Upon clicking a menu item, the color changes momentarily before reverting back to default. The menu items are actually anchor tags that redirect users to other URLs. However, since the menu and JavaScript are always included in the called URLs, I expected the class to persist.
I hope my explanation is clear enough, and any help would be greatly appreciated as this issue is really starting to frustrate me!