Js dynamic call CSS properties of small rules and examples

  • 2020-03-30 01:09:32
  • OfStack

Just saw a good article about js call CSS properties, (^_^) good! Don't forget, summarize

1. For CSS properties without underscores, the name of style. property can be used directly.

For example: obj.style.margin, obj.style.width, obj.style.left, obj.style.position, etc.

2. For CSS properties with underscores, remove each underscore and capitalize the first character after each underscore.

Such as: obj. Style. MarginTop, obj. Style. BorderLeftWidth, obj. Style. ZIndex, obj. Style. FontFamily, etc.

Since float is a reserved word in Javascript, how do you write a float in a style sheet in js?

We can't use obj.style.float directly, as this operation is invalid.

The correct method of use is to: IE: obj. Style. StyleFloat, other Mozilla browser (gecko), ff, etc with styleFloat: obj. Style. CssFloat.

Let me give you an example that makes sense:

<div onclick="alert(this.style.float);  
alert(this.style.float);"> test 1</div> 
<div onclick="alert(this.style.float);  
}alert(this.style.float);"> test 2</div> 

Related articles: