'document.body.style.color = 'blue'; document.body.style.fontSize = 18px'; does not work in Android WebKit

I have been trying to inject the following code into Android webkit, but it does not have any effect

document.body.style.color = 'blue'; 
document.body.style.fontSize = '18px'; 

on the other hand the following DOM method works

document.body.style.BackgroundColor = 'green';

I am using a Samsung Galaxy S running Android Froyo. This colour and fontSize methods work on regular web based Safari browsers but I am nt having any luck with the Android webkit browsers. Any idea what I am doing wrong?

In case these methods are not supported by Android webkit, is there any way i can determine which DOM methods and properties are supported by my WebKit based browser and which are not?

Thanks in anticipation.



Solution 1:[1]

Are the body element's direct child elements (e.g. ) absolutely positioned? If so then the document has no height (don't ask me why), you will need to give it height to give it a background color.

If you insist on doing inline styling then have you tried...

document.getElementsByTagName('body')[0].style.backgroundColor = '#00f';
document.getElementsByTagName('body')[0].style.fontSize= '18px';

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1