JavaScript gets CSS styles

Grammar:
nodeObject.style.cssProperty
Among them, nodeObject is the node object and cssProperty is the CSS property.

For example:

document.getElementById("demo").style.height; document.getElementById("demo").style.border;

Note: For CSS properties separated by "-", remove the "-" and capitalize the first letter after the "-". For example:
background-color should be written as backgroundColor
line-height should be written as lineHeight

For example:

document.getElementById("demo").style. backgroundColor; document.getElementById("demo").style.lineHeight;

For example, get the style of the node with id="demo" :

点击这里获取CSS样式

Slightly modify the above code to separate the CSS style from the HTML:

 
点击这里获取CSS样式

It can be found that the CSS style cannot be obtained after separating the CSS style from the HTML code. This is because
nodeObject.style.cssProperty
obtains the style defined by the style attribute on the DOM node. If the style attribute does not exist, or the style attribute does not define the corresponding style, it cannot Obtained.

In other words, JavaScript will not go to the