We know that getting the actual width and height of an element can use the currentStyle property in IE. However, if the width and height of the element are not displayed, then using this attribute will not be obtained, and the obtained value is auto. as follows
The code copy is as follows:
<div>abcd</div>
<script>
var div = document.getElementsByTagName('div')[0];
alert(div.currentStyle.width);
alert(div.currentStyle.height);
</script>
All outputs in IE6/7/8/9 are auto. If the width and height are set on the display, then the output is the actual width and height. as follows
1. Setting through inline style attribute
The code copy is as follows:
<div>abcd</div>
<script>
var div = document.getElementsByTagName('div')[0];
alert(div.currentStyle.width);
alert(div.currentStyle.height);
</script>
2. Settings with embed style tags through page
The code copy is as follows:
<style>
div {
width: 100px;
height: 50px;
}
</style>
<div>abcd</div>
<script>
var div = document.getElementsByTagName('div')[0];
alert(div.currentStyle.width);
alert(div.currentStyle.height);
</script>
All will output: 100px, 50px