Generally, set inline styles for elements, such as <div id="div1"></div>. To get its style, you can get or set it by document.getElementById("div1").style.width. However, if the style is in the external link or the non-line style of the page, it cannot be obtained.
In a standard browser, you can use window.getComputedStyll(obj,null)[property] to get the external link style, but in an ie browser, you can use obj.currentStyle to get it.
Complete html code:
<!DOCTYPE html><html><head> <title>js get the external link style of the element</title><base target="_blank"/> <style type="text/css"> p { width: 500px; line-height: 30px; } </style> <script src="http://VeVB.COM/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];//Or you can also get the style through window.getComputedStyle}return null;}$(document).ready(function(){$("p").click(function(){alert(getstyle(this,"width"));});}); </script></head><body> <p>If you click me, the width will pop up. </p> <p>Click me to pop up the width. </p> <p>Click me too. </p> <div><a href="http://VeVB.COM">Home</a> <a href="http://VeVB.COM/phtml/">Special Effect Library</a> <a href="http://VeVB.COM/a/bjae/nb9lb3sd.htm">Original text</a></div></body></html>The simple implementation method of obtaining external link styles of js elements is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.