Home >Web Front-end >JS Tutorial >JavaScript obtains element size and size operation summary_javascript skills

JavaScript obtains element size and size operation summary_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 16:12:281024browse

1. Get the inline style of the element

Copy code The code is as follows:

var obj = document.getElementById("test");
alert(obj.height "n" obj.width);
// 200px 200px typeof=string just displays the value in the style attribute

2. Get the calculated style

Copy code The code is as follows:

var obj = document.getElementById("test");
var style = null;
if (window.getComputedStyle) {
Style = window.getComputedStyle(obj, null); // Non-IE
} else {
Style = obj.currentStyle; // IE
}
alert("width=" style.width "nheight=" style.height);

Note: If the width and height of the element are not set, the default width and height will be returned in non-IE browsers. Return auto string

under IE

3. Get the styles written in the and