jQuery offset()Method
Example
Return the offset coordinates of a <p> element:
Try it Yourself »
Definition and Usage
The offset() method sets or returns the offset coordinates of the selected element relative to the document.
When used to return the offset:
This method returns the offset coordinates of the first matched element. It returns an object with two properties (the top and left positions in pixels).
When used to set the offset:
This method sets the offset coordinates of all matched elements.
Syntax
Return the offset coordinates:
Set the offset coordinates:
Set the offset coordinates using a function:
| Parameters | Description |
|---|---|
| {top:value,left:value} | Required when setting the offset. Specifies the top and left coordinates in pixels. Possible values:
|
| function(index,currentoffset) | Optional. Specifies a function that returns an object containing the top and left coordinates.
|
More Examples
Set offset coordinates
How to set the offset coordinates of an element.
Set offset coordinates using a function
How to set the offset coordinates of an element using a function.
Set offset coordinates for an element using an object
How to set the offset coordinates of an element using a new object.
Set offset coordinates for an element using another element's offset coordinates
How to set the offset coordinates of an element using the offset coordinates of another element.
Other Extensions
jQuery HTML/CSS Methods