0

Javascript onmousemove event not working

Hi I have an image of a map and wish to find the coordinates. The code below is not working as it should... The Javascript: window.onload(init); function init(){ var map = document.getElementById('map'); map.onmousemove = showCoords; } function showCoords(eventObj){ var coords = document.getElementById('coords'); var x = eventObj.clientX; var y = eventObj.clientY; coords.innerHTML = 'Map Coordinates: ' + x + ', ' + y; } The HTML: <img id='map' src="images/map.jpg" alt=""> <p id='coords'>Move Mouse to get coords</p>

2nd Dec 2017, 11:51 AM
horcrux88
horcrux88 - avatar
1 ответ
+ 2
change map.mousemove = showCoords; to map.mousemove = function(event) { showCoords(event) };
2nd Dec 2017, 12:21 PM
Yousaf
Yousaf - avatar