Tara Wilfred Tara Wilfred - 7 months ago 35
jQuery Question

Get Position of Element in Javascript

I am trying to get the position of an element dropped onto the canvas using the following code.

var x = $(".partitiondrop").position();
alert("Top position: " + x.top + "\nLeft position: " + x.left);

The above works fine. I would like to know if I can get the Right and Bottom positions in the same way so that I can have the area bound by the element as I need to check which elements fall inside this element.

var $partitiondrop = $(".partitiondrop");
var position = $partitiondrop.position();
position.bottom = position.top + $partitiondrop.height();
position.right = position.left + $partitiondrop.width();
alert("Top position: " + position.top + "\nLeft position: " + position.left + "\nBottom position: " + position.bottom + "\nRight position: " + position.right);