How to get mouse click coordinates relative to the parent div's top left corner instead of top left corner of the browser's viewport ?
Example : If you click on #mydiv
in the code below, how to get the coordinates relative to #mydiv
's top left corner?
mydiv.onclick = function(e) { alert(e.clientX + ' ' + e.clientY); }
#blah { position: absolute; top:50px; left:60px; width: 1000px; height: 1000px; background-color: #F0F }
#mydiv { position: absolute; top:100px; left:100px; width: 100px; height: 100px; background-color: #FF0 }
<div id="blah"><div id="mydiv">Blah</div></div>
Edited (there was a major mistake in the example).