<!DOCTYPE HTML><HTMLLang= "en"><Head> <MetaCharSet= "UTF-8"> <Metaname= "Viewport"content= "width=device-width,target-densitydpi=high-dpi,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, User-scalable=no "/> <title>JavaScript get inline style</title></Head><style>#box{width:100px;Height:100px;Background-image:URL (1.jpg);background-size:140% 140%;background-repeat:no-repeat;Border:20px Solid Rgba (0,0,0,.3);Background-clip:Border-box;background-position:-20px-20px;}</style><Body> <DivID= "box"></Div></Body></HTML><Script> //get inline style elements functionGetStyle (obj, attr) {if(window.getComputedStyle) {returngetComputedStyle (obj,NULL) [attr]; }Else{ returnObj.currentstyle[attr]; } } //Get Object function$ (ID) {returndocument.getElementById (ID); } varBox= $('Box'); //Print StyleAlert (getStyle (box,'background-position'));</Script>
JavaScript get inline style