JavaScript changes CSS style

Source: Internet
Author: User

Change the CSS style is divided into local and global, the following for you to use JavaScript specific implementation, interested friends can refer to the following

First, there are three ways to change styles locally: Directly change the style, change the className and change the csstext to change the className:document.getElementById (' obj '). Classname= "..." Change cssText:document.getElementById (' obj '). style.csstext= "width:20px;    Border:solid 1px #f00; "; Change the direct style: document.getElementById (' obj '). style.backgroundcolor= "#003366 ″ Two, the global change style realizes the real-time switching of the page style by changing the value of the href in the chain style, that is,"    Change Template Style ". First you need to give the target an ID that needs to be changed, such as the code as follows: <link rel= "stylesheet" type= "Text/css" id= "CSS" href= "Firefox.css"/> The call is simple, such as the following code : <span onclick= "javascript:document.getElementById (' CSS '). href= ' ie.css '" > Dot i change style </span>
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.