Home  >  Article  >  Web Front-end  >  Small rules and special cases of js dynamically calling css properties

Small rules and special cases of js dynamically calling css properties

高洛峰
高洛峰Original
2016-11-24 09:27:191172browse

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 containing 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 in Javascript, how do you write float in the style sheet in js?

We cannot use obj.style.float directly, 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 easier for everyone to understand:

Test 1

Test 2


Statement:
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
Previous article:Vue.js custom filterNext article:Vue.js custom filter