JavaScript Read CSS Property issues

Source: Internet
Author: User

When writing JavaScript code, it is often a problem to use Element.style.property to read only the style style defined in the HTML tag, but defined in the <style> Labels and external styles are not readable. However, browser developers have provided a property for element to get these styles. IE provides obj.currentStyle.property, while standard browsers provide a method Obj.getcomputedstyle (Obj,null).

So, you can encapsulate a method to implement the Get style

    function GetStyle (element,property) {     var stylevalue=null;     if (element.getcomputedstyle) {   stylevalue=element.getcomputedstyle (element,null) [ Property]  }else{       stylevalue=Element.currentstyle[property];   return  stylevalue; }    

JavaScript Read CSS Property issues

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.