I have an idea how to implement this, but it doesn't seem that of all the similar posts, anybody is able to give a simple example. I want to simply store the value of the toggle state of "marketing-message-global" in a cookie. If the user clicks "hide-marketing-message-btn", the toggled state will be stored in a cookie. When the user refreshes the page, the stored toggle state will be used, and hide the div that was toggled off.
<div id="marketing-message-global">
</div>
<div id="hide-marketing-message-btn">
</div>
$(document).ready(function() {
if $('#hide-marketing-message-btn").clicked()
{
$("#marketing-message-global").hide();
$.cookie("toggle-state") == true;
}
if ($.cookie("toggle-state") == true)
{
$("#marketing-message-global").hide();
}
else if ($.cookie("toggle-state") == false)
{
$("#marketing-message-global").show();
}
});
</script>
I used jquery cookie plugin (https://github.com/carhartl/jquery-cookie)
I think this should work:
1) If you want to set the cookie by some events else:
2) Setting cookie by clicking on div and performing toggle at once: