javascript - jquery save background-color in local storage -
i'm trying save change in background-color in local storage after button click, it's not saved when refreshing window. have forgotten something?
$(".btn-secondmenu").click(function(){ $(".btn-secondmenu").css('background-color', 'red'); var status = $(".btn-secondmenu"); localstorage.setitem(".btn-secondmenu", status); });
you need set color variable status
. current code sets $(".btn-secondmenu")
- jquery object localstorage.
$(".btn-secondmenu").css('background-color', localstorage.getitem(".btn-secondmenu")); //sets color localstorage on dom ready - getitem(). $(".btn-secondmenu").click(function () { $(this).css('background-color', 'red'); //use *this* set color current button var status = $(".btn-secondmenu").css('background-color'); //assign color value variable localstorage.setitem(".btn-secondmenu", status); });
Comments
Post a Comment