Im using this code:
$(this).css('backgroundcolor', localStorage.getItem('bgColorr') + " !important;");
When i write:
alert( localStorage.getItem('bgColorr') + " !important;");
It gives me the proper alert, rgb(243,102,42) !important; ….
Really getting to me.. thanks guys!
edit:
Surrounding code:
$(function() {
$(this).css('background-color', localStorage.getItem('bgColorr'));
});
var colorOptions = '#000, #fff, #abf7ae, #f6cbe9, #53c68f, #53c1c6, #538dc6, #c6536b'.split(', '),
colorDivs = [],
colorsContainer = $('#colorsContainer');
for ( var i = 0, len = colorOptions.length; i < len; i++ ) {
var div = $('<div />').css('background', colorOptions[i])[0];
colorDivs.push(div);
}
colorsContainer.append(colorDivs);
$('#header').hover(function() {
colorsContainer
.fadeIn(200)
.children('div')
.click(function() {
$('body').css('background', $(this).css('backgroundColor'));
localStorage.setItem('bgColorr', $(this).css('backgroundColor'));
});
}, function() {
colorsContainer.fadeOut(200);
});
There you go, thanks guys
'background-color'instead of'backgroundcolor'.!important. You can’t set this property from Javascript.Update:
In addition to the above, it seems that
thisis not an HTML element. You need to use a proper selector here, e.g.$('#someid')to select the element withid='someid'. If you want to change the body background, use$('body').To summarize, you should be left with: