Reputation: 14622
I have an icon <img src="res/img/b_drop.png" id="drop_1" />
. When this icon is clicked, I need a prompt to appear at some coordinates that I will calculate by the S and Y points of my #drop_
. What can I do to calculate these two points using jQuery?
Upvotes: 0
Views: 134
Reputation: 20209
offset could be what you want
$('#drop_1').on('click', function(){
var offset = $(this).offset();
alert('top - ' + offset.top + "\n left - " + offset.left);
});
This will alert the position of the element from the top and left of the document
Here is a
Upvotes: 3
Reputation: 5332
Relatively parent element:
$('#drop_1').position().left // x coord
$('#drop_1').position().top // y coord
Relatively page:
$('#drop_1').offset().left // x coord
$('#drop_1').offset().top // y coord
Upvotes: 0