Skip to content Skip to sidebar Skip to footer

Getpropertyvalue("backgroundcolor") Returns An Empty String

This is my problem: var mycss = window.getComputedStyle(myelement); returns a CSSStyleDeclaration object: CSSStyleDeclaration {0: 'animation-delay',..., backgroundColor: 'rgb(0, 0

Solution 1:

Instead of

mycss.getPropertyValue("backgroundColor");

use

mycss.getPropertyValue('background-color')

That worked for me.

Solution 2:

Within your CSSStyleDeclaration, you need to change 'backgroundColor' to 'background-color' and then call

mycss.getPropertyValue('background-color')

An example: HTML:

<head><style>body {
    background-color: lightblue;
}
</style></head><bodyid="body">
  hello world
</body>

and then calling the getPropertyValue:

var mycss = window.getComputedStyle(document.getElementById("body"));
myelement.innerHTML = mycss.getPropertyValue("background-color");

Post a Comment for "Getpropertyvalue("backgroundcolor") Returns An Empty String"