views:

109

answers:

1

This code only seems to work in Firefox. Safari and Opera don't like it:

alert($("<body>").css("background-color"));

I've tried other methods too which are even less successful.

alert(document.getElementsByTagName("body")[0].styles.backgroundColor);
alert(document.body.styles.backgroundColor);

I've tested these browsers on Mac - and haven't tested this in IE (yet). Any ideas?

+3  A: 

Try:

alert($("body").css("background-color"));

(i.e. without the angle brackets around body). See the jQuery docs on the CSS function, and the docs on jQuery Selectors.

Dominic Rodger
Yep, you don't need the whole tag as the selector, just the tag name.
Mark B
Whoops! Thanks for this guys, I knew the whole tag was for creation of elements - just slipped past me on this occasion!
Greg K