tags:

views:

48

answers:

2

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.

+2  A: 

Using offset().

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

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;
Anwar Chandra
position() is relative to the offset element not the page (like pageX and pageY on events). offset() is the better fit here.
cletus