Read styles other than inline

Source: Internet
Author: User

From: http://hi.baidu.com/lepharye/blog/item/53e622cfad5bd731f9dc61e0.html

Style sheets can be created in three ways:

Inline style: it is written in the tag. The embedded style is only valid for all tags.

Internal style sheet: it is written in the HTML

External style sheet: if many web pages are used in the same style (styles), write the style (styles(in a CSS file suffixed with .css, and then reference the CSS file on each page that requires these styles.

The following is a javascript code that reads styles other than embedded styles. It can only be read and cannot be written.

VaR Mydiv = Document. getelementbyid ( ' Mydiv ' );
If (Mydiv. currentstyle ){
VaR Width = Mydiv. currentstyle [ ' Width ' ];
Alert ( ' IE: '   + Width );
} Else   If (Window. getcomputedstyle ){
VaR Width = Window. getcomputedstyle (mydiv, Null )[ ' Width ' ]
Alert ( ' Firefox: '   + width );
}< P>

In addition, you can obtain the document in the following way under FF
. defaultview. getcomputedstyle (mydiv, null ). width
window. getcomputedstyle (mydiv, null ). width

<meta http-equiv =" Content-Type "content =" text/html; charset = UTF-8 "> <br/> <style> # test {width: 200px ;} </style> <p> This is test content <p>

RUN 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.