The difference between getcomputedstyle and style

1. Read-only and writable
The getComputedStyle method is read-only, it can only get the style, but cannot be set; while element.style can read and write, and can bend and stretch.
2. The scope of the obtained object The
getComputedStyle method obtains all the CSS property objects that are finally applied to the element (even if there is no CSS code, the default ancestors and eight generations will be displayed); and element.style can only obtain the element style attribute. CSS styles. So for a bare element <p>, the getComputedStyle method returns the value of the length attribute in the object (if any) is 190+ (according to my test FF: 192, IE9: 195, Chrome: 253, the results may be different in different environments), and element.style is 0.
3. Function
The getComputedStyle method has a very important function similar to that of the css() method - getting the pseudo-class element style
4. Compatibility
getComputedStyle method is not supported by IE6~8

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325721526&siteId=291194637