Use cssText to modify styles in batches

Source: Internet
Author: User

Copy codeThe Code is as follows:
Var element = document. getElementById ("id ");
Element. style. width = "20px ";
Element. style. height = "20px ";
Element. style. border = "solid 1px red ";

There are a lot of styles, and there are a lot of code. It is a typical process of destroying the original styles and recreating objects through JS, will increase the browser overhead.
Js has a cssText method:
Syntax: obj.style.css Text = "style ";
The above code can be modified to: Thanks to sliuqin for its correction in the message.
Element.style.css Text ("width: 20px; height: 20px; border: solid 1px red ;")
Which of the following is true?
Copy codeThe Code is as follows:
Element.style.css Text = "width: 20px; height: 20px; border: solid 1px red ;";

In this way, you can try to avoid page reflow and improve page performance.

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.