JS Get inline style
// get inline style function getcss (obj,attr) {//obj: Object, Name:style property if(obj.currentstyle ) { return obj.currentstyle[attr]; } Else { return document.defaultView.getComputedStyle (obj,null) [attr]; } }
As we all know, with document.getElementById (' element '). Style.xxx can get style information for an element, but it gets only the style rules in the DOM element style property, and the external style sheet referenced by the class attribute will not get the information we want.
The DOM standard has a global method getComputedStyle, which can get the current object style rule information, such as: getComputedStyle (obj,null). paddingleft
But it's not over, the evil IE does not support this method, it has its own implementation, that is, currentstyle, unlike the global method getComputedStyle, which is a DOM element attribute exists, such as: Obj.currentStyle.paddingLeft, in IE gets the object's left inner margin
JS Get inline style