Friday, 16 December 2011

Finding Position of an HTML element in JavaScript.

<script language="JavaScript">
function find_pos(event){
    pos_x = event.offsetX?(event.offsetX):event.pageX-document.getElementById("pointer_div").offsetLeft;
    pos_y = event.offsetY?(event.offsetY):event.pageY-document.getElementById("pointer_div").offsetTop;
}

</script>


Use in HTML Page.

HTml:-

onclick="find_pos(event);"