Why does
document.body.style.backgroundColor
not work with an external CSS style sheet? I have the following CSS:
body
{
background-color: red;
}
In my css style sheet, when I use JavaScript alert
alert(document.body.style.backgroundColor);
, it shows an empty string. You can see a working example here.
However, when I use this HTML:
<body style="background-color: red;"></body>
It correctly shows "red". Example available here.
I am seeking a clear explanation and a solution for fixing the issue in the first example.