Get element position
- The left distance of the offsetleft element relative to the parent element
- The distance of the offsetheight element relative to the upper part of the parent element
The difference between offsetleft and Style.left
- Offsetleft is read-only, Style.left is readable and writable, to change the position of the element, only using Style.left
- Offset returns a string that is returned by a number;style.left, such as "30px"
- Style.left need to be defined directly in HTML. Defined in a CSS style sheet, it is not possible to get this property
Here's a point:
This property must be declared in the element if you want to get the attribute of the element. Writing in CSS stylesheets and <style> is not available for scripting.
Also, Element.width and Element.style.width are two properties. Although the effect is the same, but Element.width is Number,element.style.width is a string
Get element Width height
- Element.offsetwidth
- Element.offsetheight
The offset property gets the width height of the element including padding, excluding margin
Element.style.width can only modify the value of a property and cannot be used to get a value
Get browser window width height
- Window.innerwidth
- Window.innerheight
- Window.outerwidth
- Window.outerheight
Scrolling properties
Returns the full width and height of the element.
JavaScript DOM element height