temporary elemental approach
This is not ideal, but you can create a temporary element when your js initiates, insert it somewhere in the document hidden (because if you do not get empty styles for webkit browsers), and then read the default background style set for this element. This will give you your base values. Then, when you compare your real element, if they are different, you know that the background is set. Obviously, the disadvantage of this method is that it cannot determine if you are setting the background to the base state.
var baseline = $('<div />').hide().appendTo('body').css('background'); var isBackgroundSet = ( element.css('background') != baseline );
If you want to avoid possible global element styles, this will break the ie system:
div { background: red; }
... you could use the following instead, but I doubt that it will work so well with older browsers:
var baseline = $('<fake />').hide().appendTo('body').css('background');
background
I spent some time on a similar problem - trying to get the original width value from the element when setting in percent. Which was much more complicated than I expected, in the end I used a similar temporary solution to the element. I also expected that, as Rene Koch does above, the getComputedStyle method will work ... it's actually annoying. Trying to spot the difference between the original CSS world and the runtime of the CSS world is a difficult task.
Pebbl
source share