Javascript dynamic style setting example analysis _ javascript tips-js tutorial

Source: Internet
Author: User
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  
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.