Home > Web Front-end > JS Tutorial > Small rules and examples of dynamically calling css attributes in js_javascript skills

Small rules and examples of dynamically calling css attributes in js_javascript skills

WBOY
Release: 2016-05-16 17:06:33
Original
1339 people have browsed it

I just saw a good article on how to use js to call css attributes. (^_^) It’s not bad! To avoid forgetting, let’s summarize

1. For css attributes without an underscore, 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 containing underscores, remove each underscore and replace the first character after each underscore with uppercase letters.

Such as: obj.style.marginTop, obj.style.borderLeftWidth, obj.style.zIndex, obj.style.fontFamily, etc.

Because float is a reserved word in 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 usage method is: IE: obj.style.styleFloat, other browsers such as Mozilla (gecko), ff, etc. use styleFloat: obj.style.cssFloat.

Give me an example to make it easy for everyone to understand:

Copy the code The code is as follows:

Test 1

Test 2

Related labels:
js
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template