JavaScript (retrieve or set the width, height, and coordinates of HTML elements)
Settings:
View plaincopy to clipboardprint?
document. getelementbyid ('id '). style. width = value
document. getelementbyid ('id '). style. height = value
document. getelementbyid ('id '). style. top = value
document. getelementbyid ('id '). style. left = value
document. getelementbyid ('id '). style. width = value
document. getelementbyid ('id '). style. height = value
document. getelementbyid ('id '). style. top = value
document. getelementbyid ('id '). style. left = value
Obtain:
View plaincopy to clipboardprint?
Value = Document. getelementbyid ('id'). offsetleft
Value = Document. getelementbyid ('id'). offsettop
Value = Document. getelementbyid ('id'). offsetwidth
Value = Document. getelementbyid ('id'). offsetheight
Value = Document. getelementbyid ('id'). offsetleft
Value = Document. getelementbyid ('id'). offsettop
Value = Document. getelementbyid ('id'). offsetwidth
Value = Document. getelementbyid ('id'). offsetheight
View plaincopy to clipboardprint?
<SCRIPT>
Function findposition (oelement)
{
VaR X2 = 0;
VaR y2 = 0;
VaR width = oelement. offsetwidth;
VaR Height = oelement. offsetheight;
Alert (width + "=" + height );
If (typeof (oelement. offsetparent )! = 'Undefined ')
{
For (VAR posx = 0, Posy = 0; oelement = oelement. offsetparent)
{
Posx + = oelement. offsetleft;
Posy + = oelement. offsettop;
}
X2 = posx + width;
Y2 = posy + height;
Return [posx, Posy, X2, y2];
} Else {
X2 = oelement. x + width;
Y2 = oelement. Y + height;
Return [oelement. X, oelement. Y, X2, y2];
}
}
</SCRIPT>
<SCRIPT>
Function findposition (oelement)
{
VaR X2 = 0;
VaR y2 = 0;
VaR width = oelement. offsetwidth;
VaR Height = oelement. offsetheight;
Alert (width + "=" + height );
If (typeof (oelement. offsetparent )! = 'Undefined ')
{
For (VAR posx = 0, Posy = 0; oelement = oelement. offsetparent)
{
Posx + = oelement. offsetleft;
Posy + = oelement. offsettop;
}
X2 = posx + width;
Y2 = posy + height;
Return [posx, Posy, X2, y2];
} Else {
X2 = oelement. x + width;
Y2 = oelement. Y + height;
Return [oelement. X, oelement. Y, X2, y2];
}
}
</SCRIPT>
View plaincopy to clipboardprint?
This is a layer. This is a layer.