JavaScript gets inline and non-inline styles--compatible notation

Source: Internet
Author: User

Style : Gets the inline style; currentstyle: Gets the calculated style, also called the current style, the final style.
Pros: You can get the final style of an element, including the default value of the browser, rather than just the inline style, as a style, so it's more common.
Note: You cannot get composite styles such as background property values, only a single style such as Background-color, and so on.

alert (Oabc.currentstyle);
IE8 and Opera 11 pop Up "Object Cssstyledeclaration"; FF 12, Chrome 14, Safari 5 pops up "undefined".

var oabc = document.getElementById ("abc");
if (Oabc.currentstyle) {
IE, Opera
Alert ("I support Currentstyle");
} else {
FF, Chrome, Safari
Alert ("I do not support Currentstyle");
}

In fact, in the FF browser we can use getComputedStyle (obj,false) to achieve the same effect as currentstyle under IE.

getComputedStyle (Obj,false): In the new version of FF only the first parameter, that is, the Operation object, the second parameter write "False" is also common use, the purpose is to be compatible with the old version of the Firefox browser.

Compatible wording:

var oabc = document.getElementById ("abc");
if (Oabc.currentstyle) {
IE, Opera
Alert ("I support Currentstyle");
alert (oAbc.currentStyle.width);
} else {
FF, Chrome, Safari
Alert ("I do not support Currentstyle");
Alert (getComputedStyle (oabc,false). width);
}

JavaScript gets inline and non-inline styles--compatible notation

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.