簡單獲取目標css的屬性方法 - TerryLee7788/JS_test GitHub Wiki

先附上參考網址...
https://developer.mozilla.org/en-US/docs/Web/API/window.getComputedStyle?redirectlocale=en-US&redirectslug=DOM%2Fwindow.getComputedStyle

HTML code

<style>
  #terry{ height:172px; }
</style>

<div id="terry">
  hihi!~ I'm Terry~
</div>

Javascript code

function getTargetStyle(target, style){
    var cur = window.getComputedStyle(target, null).getPropertyValue(style);
    return cur;
}

var terry        = document.getElementById('terry');
var terry_height = getTargetStyle(terry, 'height');

console.log(terry_height);  //172px
⚠️ **GitHub.com Fallback** ⚠️