私はCSSクラスを使用する単純なdivを持っていますが、これはcolor
とbackground-color
というプロパティセットを持っています。getComputedStyleはCSSStyleDeclarationを返しますが、アクセス時にはすべてのプロパティが空です
var div = document.createElement("div");
div.classList.add("my-css-class");
container.appendChild(div);
//This prints out a CSSStyleDeclaration object. This is a large object to which I see `color` and `backgroundColor`
console.log(getComputedStyle(div));
//this gives me an empty string
console.log(getComputedStyle(div).color);
//this gives me an empty string
console.log(getComputedStyle(div).getPropertyValue("color"));
CSSStyleDeclarationのプロパティにアクセスできないのはなぜですか?私はそれが私の最初のログからそこにあることを知っています。私は見ることができますcolor: "rgb(82, 194, 145)"
JSFiddleまたはCodePenで問題を再現できますか? – swider
ありがとうございました@swider。私は今日JSFiddleで初めて座ったので、結果として解決策を見つけました。 – Clark