Web Developers and programmers code snippets

JavaScript Get mouse click position within an element

Older browsers such as IE 7 & 8 use different event properties to reveal the mouse click coordinates within an element.

$('img').click(function(e) { var position = 'X: ' + (e.layerX || e.offsetX) + ' Y: ' + (e.layerY || e.offsetY); alert('Click position within image: ' + position); });
Posted by

Most Recent

Most Viewed