I just saw a good article about using js to call css properties. (^_^) It’s not bad! To avoid forgetting, summarize it
1. For css attributes without a dash, generally use the style. attribute name directly.
Such as: obj.style.margin, obj.style.width, obj.style.left, obj.style.position, etc.
2. For CSS attributes that contain underscores, remove each underscore and change the first character after each underscore to uppercase.
Such as: obj.style.marginTop, obj.style.borderLeftWidth, obj.style.zIndex, obj.style.fontFamily, etc.
Because float is a reserved word of Javascript, how to write float in the style sheet in js?
We cannot use obj.style.float directly, as this operation is invalid.
The correct way to use it is: IE: obj.style.styleFloat, other browsers such as Mozilla (gecko), ff, etc. use styleFloat: obj.style.cssFloat.
Let me give you an example to make it easier for everyone to understand:
Copy the code code as follows:
<divonclick="alert(this.style.float);
this.style.float='left';
alert(this.style.float);">Test 1</div>
<divonclick="alert(this.style.float);
if(this.style.cssFloat){this.style.cssFloat='left';
}else{this.style.styleFloat='left';
}alert(this.style.float);">Test 2</div>