JS using the getComputedStyle () method to get CSS property values

Source: Internet
Author: User

In the process of debugging the Web page, often use JS to get the elements of the CSS style, there are many ways, now only I often use the method summarized as follows:

1. Obj.style: This method can only be JS can only get written in the HTML tag in the Style property of the value (style= "..."), and can not get defined in <style type= "Text/css" > inside the property.

2. The Obj.currentstyle method is used in IE, and FF is the getComputedStyle method

The DOM2-level style enhances the Document.defaultview and provides the getComputedStyle () method. This method takes two parameters: to get the element of the calculated style and a pseudo-element string (for example, ": after"). If no pseudo-element information is required, the second argument can be null. The Getcomputerstyle () method returns a Cssstyledeclaration object that contains all the computed styles of the current element. Take the following HTML page as an example:

To be Continued ...

JS using the getComputedStyle () method to get CSS property values

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.