Shruti
Shruti

Reputation: 721

Identify the position for particular element using jquery

How to identify the x axis and y-axis of particluar element using jquery. Like we use pageX and pageY to identify the mouse pointer's position.

Upvotes: 1

Views: 4932

Answers (2)

Anwar Chandra
Anwar Chandra

Reputation: 8638

there is position() function that return Object{top,left}

var p = $("p:first");
var position = p.position();
var left = position.left;
var top = position.top;

Upvotes: 2

cletus
cletus

Reputation: 625077

Using offset().

var p = $("p:last");
var offset = p.offset();
p.html( "left: " + offset.left + ", top: " + offset.top );

Upvotes: 7

Related Questions