Forum Moderators: open
Need some help here. It is rather javascript question.
I need to get image top and left coordinates on mouse click.
And the problem is that i can not set image style="position:absolute;".
And without position:absolute i can get only image height and widht with parseInt(image1.width) but not top and left.
Please advise.
<script type="text/javascript">
<!--
function clickHandler(e) {
var top = 0, left = 0;
if (!e) { e = window.event; }
var myTarget = e.currentTarget;
if (!myTarget) {
myTarget = e.srcElement;
}
else if (myTarget == "undefined") {
myTarget = e.srcElement;
}
while(myTarget!= document.body) {
top += myTarget.offsetTop;
left += myTarget.offsetLeft;
myTarget = myTarget.offsetParent;
}
alert("left: " + left +
"\ntop: " + top);
}
//-->
</script>
...
<div style="margin:20px;"
onclick="clickHandler(event);">
Test layer...
</div>
Jordan