Style, Currentstyle, runtimestyle distinction Analysis _javascript Skills

Source: Internet
Author: User
1, Obj.style only get inline style (inline style) is written in the tag, he can not access those links to external CSS and in the head of the <style> declaration style.
So it must be recognized that in those pages that use an external CSS file, if you use style to assign a value, such as obj.style= "color:red"; Obviously the effect is correct, and the mystery is simply adding a style attribute to the object's tag. It is presented in the order of priority from small to large.
2, Obj.currentstyle is so much more powerful that he can get a style about all the positions of the node, but he also takes precedence, which means that what he is pointing to is what style he refers to, the following code font priority is blue, and that Currentstyle.color is blue. , of course, this time Style.color will also be blue.
Copy Code code as follows:

<meta http-equiv= "Content-type" content= "text/html; Charset=iso-8859-1 ">
<title>testStyle</title>
<style>
. lala{
Color:yellow;
}
</style>
<body>
<div id= "tt" style= "Color:blue;" class= "Lala" >1111</div>
</body>
<script>
Alert (document.getElementById ("tt"). Currentstyle.color);
</script>

If you remove the above <div> style for <div id= "tt" class= "Lala" &GT;1111&LT;/DIV&GT; Then Currentstyle.color becomes yellow according to priority, but Style.color is empty at this time.
3, Runtimestyle Simple is that you can assign a value to a node's style, he will become the highest priority node style.
Such as:
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01//en" "HTTP://WWW.W3.ORG/TR/HTML4/STRICT.DTD" >
<meta http-equiv= "Content-type" content= "text/html; Charset=iso-8859-1 ">
<style>
. lala{
Color:yellow;
}</style>
<body>
<div id= "tt" style= "Color:blue;" class= "Lala" >1111</div>
</body>
<script>
document.getElementById ("tt"). runtimestyle.color= "BLACK";
Alert (document.getElementById ("tt"). Currentstyle.color);
Alert (document.getElementById ("tt"). Runtimestyle.color);
Alert (document.getElementById ("tt"). Style.color);
</script>

At this point, the color of the page display word is runtimestyle. But only Currentstyle.color and runtimestyle themselves can get this value, and Style.color is still the blue in tag.

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.