Saturday, 21 July 2012

jQuery x y document coordinates of DOM object

offset()
Get the current offset of the first matched element, in pixels, relative to the document.
position()
Gets the top and left position of an element relative to its offset parent.

            var x = $("#wrapper2").offset().left;
            var y = $("#wrapper2").offset().top;

            console.log('x: ' + x + ' y: ' + y);
                        output:
            x: 53 y: 177
 
         hope it helps what you're looking for.

No comments:

Post a Comment