Js is used to obtain the element external link style. js is used to obtain the element style.
This article describes how to obtain the element external link style by js. Share it with you for your reference. The specific analysis is as follows:
Set the row style for the element, such as <div id = "div1" style = "width: 500px;"> </div>. To get its style, you can get or set it by document. getElementById ("div1"). style. width. However, if the style is in the outer link or the non-row style of the page, it cannot be obtained.
In the standard browser, you can use window. getComputedStyll (obj, null) [property] to obtain the external link style, but in IE, you can use obj. currentStyle.
The complete html code is as follows:
Copy codeThe Code is as follows: <! DOCTYPE html>
<Html>
<Head>
<Title> js get element external link styles </title> <base target = "_ blank"/>
<Style type = "text/css">
P {
Width: 500px;
Line-height: 30px;
}
</Style>
<Script src = "jquery/jquery-1.11.2.min.js">
</Script>
<Script>
Function getstyle (obj, property ){
If (obj. currentStyle ){
Return obj. currentStyle [property];
} Else if (window. getComputedStyle ){
Return document. defaultView. getComputedStyle (obj, null) [property]; // you can also use window. getComputedStyle to obtain the style.
}
Return null;
}
$ (Document). ready (function (){
$ ("P"). click (function (){
Alert (getstyle (this, "width "));
});
});
</Script>
</Head>
<Body>
<P style = "width: 750px;"> if you click "I", the width is displayed. </P>
<P> click "I" to display the width. </P>
<P> click me ~ O (worker _ worker) O ~. </P>
</Body>
</Html>
I hope this article will help you design javascript programs.