-
- 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
Read More:
- How to Solve the error: initialize failed invalid dom
- @requestbody: How to Use or Not Use
- CSS to achieve dynamic display of picture text by mouse touch
- Javascript: How to Use Date.Now() to implement front-end frequency limit
- Vue2.0: How to Use vue3 api to encapsulate Axios
- JS: How to Solve split, join, toString Use error
- How to use HPQC on Chrome browser
- How to use Runtime.getRuntime().Exec()
- Vue Import element-plus Error: Failed to resolve import “element-pluslibtheme-chalkindex.css“ from “src
- Vue: initialize failed: invalid DOM [How to Solve]
- The addition, deletion and modification of DOM in JS Foundation
- [Solved] Echarts Error: Uncaught (in promise) Error: Initialize failed: invalid dom.
- [Solved] Vue echarts Error: Initialize failed: invalid dom.
- Syntax Error: Error: PostCSS received undefined instead of CSS string
- Vue JS import font.css error [How to Solve]
- CSS text more than 2 lines hidden and show ellipsis
- [Solved] Vue Import swiper.css Error: Module not found…
- [Solved] echarts Draw Errror: echarts-d9fd185e.js:31447 Uncaught (in promise) Error: Initialize failed: invalid dom.
- How to Solve Vue add element Install Error
- [Solved] Syntax Error: Error: PostCSS received undefined instead of CSS string