JavaScript inline style and non-inline style fetching method

Source: Internet
Author: User

<!DOCTYPE HTML><HTMLLang= "en"><Head>    <MetaCharSet= "UTF-8">    <title></title>    <styletype= "Text/css">. style001{width:300px;Height:300px;margin:20px;padding:30px;Border:20px Grey Solid;Background-color:Lightgray;Display:Inline-block;}    </style>    <Scripttype= "Text/javascript">window.onload= function(){        varODiv1=Document.getelementsbyclassname ('style001')[0]; varODiv2=Document.getelementsbyclassname ('style002')[0]; varabtn=document.getElementsByTagName ('input'); abtn[0].onclick= function(){            varJsonstyle= {}; if( This. Currentstyle) {                //IEJsonstyle={Width:odiv1.currentstyle.width,height:odiv1.currentstyle.height,background:o            Div1.currentStyle.backgroundColor}; }            Else            {                //FFJsonstyle={Width:getcomputedstyle (ODIV1,false). Width,height:getcomputedstyle (ODiv1,false). Height,background:getcomputedstyle (ODiv1,false). BackgroundColor}} odiv1.innerhtml+= '<br> Wide'+Jsonstyle.width+ '<br> High' +Jsonstyle.height+ '<br> Background Color' +Jsonstyle.background;        }; abtn[1].onclick= function(){            varJsonstyle= {}; Jsonstyle={width:odiv2.style.width,height:odiv2.style.height,background: This. Style.backgroundcolor}; Odiv2.innerhtml+= '<br> Wide'+Jsonstyle.width+ '<br> High' +Jsonstyle.height+ '<br> Background Color' +Jsonstyle.background;        }; abtn[2].onclick= function() {ODiv1.style.backgroundColor= 'Blue'; ODiv2.style.backgroundColor= 'Blue';    };    }; </Script></Head><Body><Divclass= "style001">Restrained style</Div><Divclass= "style002"style= "width:300px;height:300px;margin:20px;padding:30px;border:20px grey Solid;background-color:lightgray; Display:inline-block; ">inline style</Div><BR/><inputtype= "button"value= "Get restrained style"ID= "BTN1"/><inputtype= "button"value= "Get inline style"ID= "BTN2"/><inputtype= "button"value= "Set inline style"ID= "Btn3"/><P>Through oDiv.style.width = 50+ ' px '; set the inline style</P></Body></HTML>

JavaScript inline style and non-inline style fetching method

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.