I am trying to get top and left attributes from element on page with jquery but it's not working.
Can you tell me how it's possible?
Thanks for any response
HTML code:
<div style="position: absolute; left: 370px; top: 0px;">
<img class="name" src="image.jpg"/>
</div>
JQuery code:
$('body').on('click', '.name', function(){
top = $(this).parent().css('top');
left = $(this).parent().css('left');
alert("Top: " + top + ",Left: " + left);
});
JQuery response:
Top: [object Window],Left: 185px
windowalso has atopproperty :) A good reminder that you should use descriptive variable names and avoid global variables