Learn to use jQuery position method with demo


Learn to use jQuery position method with demo

Learn to use jQuery position method with demo

The $.position method of jQuery

The jQuery position method is used to return position or coordinates of the given element. The coordinates are relative to the parent element of given element and values are in pixels.

See an example of position method

In order to return or set the coordinates relative to document use the offset method of jQuery.

The $.position method will get the coordinates of the first matched element if there are multiple occurrences of the matched element.

Syntax of position() method

The basic syntax to get coordinates:

$(“element”).position();

Following is an example of using the position jQuery method.

Getting coordinates example

In the following example, we have used a div element along with a span element. As you click the button, the alert will show the coordinates of the span element.

jQuery position get

Experience this example online



 

Further reading: jQuery offset



Was this article helpful?

Related Articles

Leave A Comment?