How to get CSS style by JavaScript
This article mainly introduces JavaScript how to obtain the relevant knowledge of CSS style, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value, I believe you will have something to gain after reading this JavaScript how to obtain CSS style article, let's take a look at it.
Syntax:
NodeObject.style.cssProperty
Where nodeObject is the node object and cssProperty is the CSS attribute.
For example:
?
one
two
Document.getElementById ("demo"). Style.height
Document.getElementById ("demo"). Style.border
Note: for CSS attributes separated by "-", remove "-" and capitalize the first letter after "-". For example:
Background-color is going to write backgroundColor
Line-height is going to write lineHeight
For example:
Document.getElementById ("demo") style. BackgroundColor
Document.getElementById ("demo"). Style.lineHeight
For example, get the style of the node of id= "demo":
Click here to get the CSS style
How to set and modify CSS style by JavaScript
Syntax:
NodeObject.style.cssProperty=newStyle
Where nodeObject is the node object, cssProperty is the CSS attribute, and newStyle is the value of the CSS attribute.
Note: for CSS attributes separated by "-", remove "-" and capitalize the first letter after "-".
For example:
Document.getElementById ("demo") .style.height = "50px"
Document.getElementById ("demo") .style.border = "1px solid # ddd"
Document.getElementById ("demo") .style.backgroundColor = "# ccc"
Document.getElementById ("demo") .style.textAlign = "center"
For example, style the node of id= "demo":
This is the end of the article on "how JavaScript gets the CSS style". Thank you for reading! I believe you all have a certain understanding of "how JavaScript obtains CSS style" knowledge. If you want to learn more, you are welcome to follow the industry information channel.