This article mainly introduces how to dynamically set styles in javascript, and analyzes the error points and related usage skills of style operations in javascript, for more information about how to dynamically set styles in javascript, see the following example. Share it with you for your reference. The specific analysis is as follows:
Dynamic style Modification
1. Easy to error: modifying the style of an element is not a class attribute, but a className attribute.
2. Easy to troubleshoot: Use "style. attribute name" to modify the style attributes separately. Note that the attribute name in css is in javascript.
During the operation, the attribute names may be different, mainly in those attributes that contain-, because
In javascript-it cannot be an attribute or a class name. In CSS, the background color is background-clolor, while in javascript, the background color is style. background; the element style name is class, which is the className attribute in javascript; font-size-> style. fontSize; margin-top-> style. marginTop
3. Modify the style of the control separately
1. Example 1
Dynamic style Modification