LoginSignup
0
2

More than 5 years have passed since last update.

JavaScriptからCSSのプロパティが取得できない

Posted at

おっさんは昨日喰ったものさえ忘れる

初心者および、10年ぐらい前に一度ハマっただけのおっさんのために。

こうする

html
<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <title>Display</title>
    <style>
#display-test {
    display:block;
    color:red;
}
    </style>
</head>
<body>
    <div id="display-test">Display test.</div>

<script>
var d = document.getElementById('display-test');
console.log(d.style.display);  // とれない
console.log((d.currentStyle || document.defaultView.getComputedStyle(d, '')).display);  // とれる
</script>

</body>
</html>

くわしくは

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2