JavaScript gets a simple way to get CSS between-line style, inline style and outside chain style _javascript tips

Source: Internet
Author: User

"Inter-row style fetch"

<div id= ' div1 ' style= ' backgroud:red ' > Test </div>

<script>

var Odiv=document.getelementbyid  (' Div1 ');    First get the element label to get the style, that is, get to Div1

Console.log (odiv.style.background);  So we can get to the style of the rows

</script>

"Inline style fetch"

 <script>

var odiv=document.getelementbyid (' Div1 ');  Gets the element label to get the style, that is, get to Div1

//console.log (getComputedStyle (odiv,null). background);   getComputedStyle ("element", "pseudo class") is obtained after the calculated style, the second argument is pseudo class, if not directly using null  but the evil IE8 and not supported so need to use the following method

//console.log ( Currentstyle.background)  This only IE itself support is also acquired to the computed style

console (Window.getcomputedstyle?getcomputedstyle odiv      , null). Background:odiv.currentStyle); Cross-browser compatibility

</script>

</body>

 
 

"Outer chain style fetch"

 
 

"Outer chain style sheet"

. div2{

background:red;

}

The above JavaScript to get CSS line style, inline style and outside the chain style of the simple method is small to share the whole content of everyone, hope to give you a reference, also hope that we support cloud habitat community.

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.