Q:

javascript onmousemove get relative coordinates

function aim() {
    var mousex = ?
}

<div class="gameArea" onmousemove="aim();"> </div>

I can't find how to get the mouse coordinates for an onmousemove event in javascript.

A:

var guide = null;

function aim(event) {
    if(window.event)
        event = window.event; //grrr IE
    var mousex = event.clientX - guide.offsetLeft;
    alert('mouse x' + mousex)
}
function init() {
    guide = document.getElementById("guide")
    guide.onmousemove = aim;
}

<body onload="init();">

This appears to work on both browsers. I cant do onmousemove="aim();" in html because it doesn't pass the mousemove event object.

