I'm attempting to change the body color using the options provided in a dropdown menu and saving those changes so when the user refreshes the page, the background color will be equal to what they set it as. However I'm having a problem in changing the background color according to the dropdown menu options.
HTML
<button class="btn-secondmenu">Button</button>
<select name="colors" id="colors">
<option value="red">Red</option>
<option value="green" selected="selected">Green</option>
<option value="yellow">Yellow</option>
<option value="black">Black</option>
</select>
JS
$(function(){
var select = document.getElementById("colors");
select.onchange = function(){
var selectedColor = select.options[select.selectedIndex].value;
alert(selectedString);
}
if (localStorage.getItem('background') !== null) {
getColour = localStorage.background;
$('.bdy').css('background', getColour);
} else {
getColour = 'green';
}
$('.btn-secondmenu').click(function(){
if(getColour == 'blue'){
localStorage.removeItem('background');
$('.bdy').css('background', 'red');
localStorage.setItem('background', 'red');
} else {
getColour = 'blue';
localStorage.removeItem('background');
$('.bdy').css('background', 'blue');
localStorage.setItem('background', 'blue');
}
});
});
Any suggestions would be greatly appreciated, thank you!