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>
1 Resposta
+ 2
change
map.mousemove = showCoords;
to
map.mousemove = function(event) { showCoords(event) };