-
- Modify styles through JS: the styles modified by this method are inline styles with high priority. However, if “! Important” is used in the style, the modification of JS will not work.
Syntax: element.style.styleName = styleValue ;
The style value must be a string
Note: If the style of css contains " - " , this name is not legal in JS, you need to change this style name to camel naming, remove the " - " and change the
initial letter to uppercase.
Read style:
Syntax: element.style.styleName
The styles set and read through the style property are inline styles
-
- get the display style of the current element:
Syntax: element.currentStyle.styleName
currentStyle is only supported by IE browser
In other browsers, you can use the getcomputedstyle() method to get the current style of the element. This method is a window method and can be used directly. This method will return a style object that encapsulates the corresponding style of the current element.
Two parameters are required
The first: the element to get the style
The second: you can pass a pseudo-element, which is usually null
Note: the styles obtained through currentstyle and getcomputestyle are read-only and cannot be modified. If you want to modify them, you must use the style property </OL> to modify them