views:

218

answers:

2

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 = $('').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

A: 

Your problem is not in getItem or anything, but the capitalization of your CSS property name. It's backgroundColor, not backgroundcolor.

Matti Virkkunen
not it's not. it's background-color
Matt Ellen
backgroundColor and background-color are equally acceptable in jQuery.
Matti Virkkunen
@Matt: Actually, both are correct.
interjay
guys, obviously both works since the alert is showing up correct, the css property isnt changing, i think thats the weak spot..
Noor
...but your alert has nothing to do with the CSS property name
Matti Virkkunen
no but i've set the bgColorr through that property...wonder what's causing this
Noor
Well, I for one couldn't get the non-capitalized version to work when I tried it.
Matti Virkkunen
im not sure what i wrote there, you're probably right
Noor
+3  A: 
  • Use 'background-color' instead of 'backgroundcolor'.
  • Remove the !important. You can't set this property from Javascript.
  • You shouldn't put the semicolon at the end of the value.

Update:

In addition to the above, it seems that this is not an HTML element. You need to use a proper selector here, e.g. $('#someid') to select the element with id='someid'. If you want to change the body background, use $('body').

To summarize, you should be left with:

$('body').css('background-color', localStorage.getItem('bgColorr'));
interjay
I allready tried that, and i did it again now just incase i did it wrong last time.. nothing happened..
Noor
@Noor Try with the code I posted now.
interjay
It's still not working.. maybe I shouldn't use $(this)? thanks for trying to help me!
Noor