Two ways for native js to change css styles

Source: Internet
Author: User
This article describes in detail how to change the css style using native javascript code. The following describes two ways for native js to change CSS styles:

1In javascript codeNode.style.css Text = "css expression 1; css expression 2; css expression 3"Directly change the CSS style.

2Set a style for a specific class such as "active class" in the CSS style sheet (the active class here is assumed and does not exist for the moment), and then passNode. classname = "active"Add the style settings of the active class to the node in the CSS style sheet.

The following is a detailed description of the html code:

      

It's just a simple p, and the running result is

First, use the first method mentioned above to change the css style and write the following javascript code:

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.