Home > Article > Web Front-end > getComputedStyle and currentStyle get style (style/class)_javascript skills
Everyone knows that you can get the style information of an element using document.getElementById('element').style.xxx, but it only gets the style rules in the style attribute of the DOM element. For external style sheets referenced through the class attribute , we won’t be able to get the information we want.
There is a global method getComputedStyle in the DOM standard, which can obtain the current object style rule information, such as: getComputedStyle(obj,null).paddingLeft, which can obtain the left padding of the object. But things are not over yet. The evil IE does not support this method. It has its own implementation method, which is currentStyle. Different from the global method getComputedStyle, it exists as a DOM element attribute, such as: obj.currentStyle.paddingLeft. In IE The left inner margin of the object is obtained. The compatibility is written as follows: