SoFunction
Updated on 2025-04-10

Small rules and examples of dynamic call to css attributes by js

I just saw a good article introducing js calling css attribute, (^_^) is not bad! I won't forget myself, let's summarize

1. For css attributes without a mark, you can usually use the style. attribute name directly.

Such as:,,,, etc.

2. For the css attribute containing the middle mark, remove each middle mark and change the first character after each middle mark to capitalize.

Such as:,,,, etc.

Because float is a reserved word for Javascript, how can I write float in style sheets in js?

We cannot use it directly, as this operation is invalid.

The correct way to use it is to use styleFloat: for other browsers: Mozilla (gecko), ff, etc.

Give an example to understand:

Copy the codeThe code is as follows:

<div onclick="alert();  

='left';  

alert();">Test 1</div>

<div onclick="alert();  

if(){='left';  

}else{='left';  

}alert();">Test 2</div>