I have the task of setting a cookie for the menu. I have a horizontal menu. When I click on the menu, the menu identifier is set to a cookie. But when I select the next menu, the cookie shows that the first value is input. To do this, I used $.removeCookie("activeDivId"); . But it does not work properly. How can I solve this problem? HTML code
<div class="menuBar"> <div id="divHome" class="menuHeader ui-corner-top"> <span><a href="#" onclick="Home()" id="home">Home</a></span> </div> <div id="divNewTransaction" class="menuHeader ui-corner-top"> <span><a href="#" onclick="NewTransaction()" >New Transaction</a></span> </div> </div>
Javascript file
$(document).ready(function () { $(".menuHeader").click(function () { $.removeCookie("activeDivId"); $.cookie("activeDivId", this.id); }); alert(document.cookie); var activeDivId = $.cookie("activeDivId") ? $.cookie("activeDivId") : "divHome"; $("#" + activeDivId).addClass("menuHeaderActive"); });
source share