Why is js getting the width and height of an element empty?

the following acquisition is empty, how can I get it? Do not use offsetWidth

-sharpdiv {
        width: 100px;
        height: 100px;
        background-color: red;
    }
    
    var div = document.getElementById("div")
   console.log(div.style.width)
Aug.25,2021

if your element is not styled in style , then you can't get it through dom.style.XXX .

you can get it from getComputedStyle . Specific usage

</div>[getComputedStyle]<a>1</a>[currentStyle]<a>2</a>:

var ele = document.getElementById("div");
var style = window.getComputedStyle ? 
    window.getComputedStyle(ele, "") : 
    ele.currentStyle;
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b38f40-34505.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b38f40-34505.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?