Set cookie dynamic based on id
in Using jQuery
•
9 years ago
Hello!
I have an Array of items, comming from a data source. What I want to do is to change the background color of the outher div when the user clicks on it. I have and id that can be a number from 1 up to let's say 100. I cannot do this with CSS because of the page will be refreshed after a click so I would like to set a cookie for this. However I cannot figure out how to do this.
I use thie jquery.cookies.js
<div class="xxx" id="{@ID}">
<a class="yyy" href="example.aspx?Title=@Title">
<div class="zzz">My dynamic data comes here ..</div>
</a>
</div>
I have tried with something like this.. but I know is not right. Any thoughts?
$('.test').on('click',function(){
//var x = (this.id);
//alert(x);
$(this.id).css("background-color","red");
$.cookie('MyCookie', 'RED');
});
var MyCookie = $.cookie('MyCookie');
if (MyCookie == 'RED') {
$(x).css("background-color","red");
};
1