The problem of setting style attribute of dom Node

I did an experiment today

node.style ["margin-left"] =" 100px"

this code successfully sets the css property

but when I output node.style in the console, I don"t find the attribute margin-left. I just see

.

clipboard.png

marginLeft

clipboard.png

visit node.style ["margin-left"] again and you will get 100px

.

question:

  • Why there is no margin-left property in the object and its prototype, but I only set style.marginLeft , access margin-left still has a value and change one side and the other will change
Mar.14,2021
The properties of

css can be accessed through camelCase in the style object of js. The advantage of this is that you can use .margin left or ["marginLeft"]. In fact, you can also access it in the form of a trumpet, but you cannot use .margin-left (js syntax does not allow it), but you can use ["margin"] to access it. The two kinds of access in the dom object are equivalent, so the two properties are also modified by Synchronize.

Menu