<!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