JavaScript Dynamic Operation CSS Summary

Source: Internet
Author: User

First, use JS Operation CSS the notation of the property

1 , for non-underlined CSS properties are generally used directly style. property name.

such as: Obj.style.margin , Obj.style.width , Obj.style.left , obj.style.position

2 , for those containing the underlined CSS attribute, remove each underline and change the first character after each one to uppercase.

such as: Obj.style.marginTop , Obj.style.borderLeftWidth , Obj.style.zIndex , obj.style.fontFamily wait

3 , JS Operation CSS Float special wording for attributes

because float is a JavaScript reserved words, we cannot directly use obj.style.float to use, so the operation is not valid. The correct way to use it is:IE:obj.style.styleFloat, other browsers Mozilla (Gecko), FF , etc. with styleFloat:obj.style.cssFloat.

Second, use JS Get CSS Property Value

1 , get in-line Style : Obj.style. property name. <div id= "css88" class= "ss" style= "width:200px; height:200px; background: #333333" >js get CSS Property Value </div> Cannot access class .

2 , Get Class internal and Link outside the Css Properties: IE is used in the obj.currentstyle[" property name "] method, and FF it's used. getComputedStyle Method

third, the use JS Give CSS Property Assignment Value

1 , Assignment class Properties

Assignment Value: document.getElementById (' Ceil '). ClassName = "Class1";

if it has multiple values: document.getElementById (' Ceil '). ClassName = "Class1 class2 class3";

2 , Obj.style.cssText sets an object's CSS style

document.getElementById (' navition '). Style.csstext = " you a CSS Code ';

JavaScript Dynamic Operation CSS Summary

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.