I have a <select>
element that I want to use to change the background of my web page. I got the background to successfully change (although in a pretty inelegant manner), and I was wondering if there is an easy way to "save" this so that whenever the user leaves and comes back to the web page, the background is what they chose.
I was tinkering around with cookies and localStorage to accomplish this but never got anything to work.
HTML:
<select id="settingBackground">
<option name="default">Default</option>
<option name="thankshaking">Background 2</option>
</select>
JavaScript:
$(document).ready(function () {
$('#settingBackground').on('change', function () {
if (this.value == "Default") {
// Change background
$('body').css("background", "#1e8cd4");
$('body').css("color", "#fff");
} else if (this.value == "Background 2") {
// Change background
$('body').css("background", "url('http://i.imgur.com/cV7PKqh.jpg') no-repeat center center fixed");
$('body').css("background-size", "cover");
$('body').css("color", "#000");
}
});
});