I have some mouse-tracking code that isn’t working as expected in IE that basically boils down to the HTML below. I’ve tried this in both IE7 and IE8.
The part that’s unexpected is when you mouse over the text in the disabled textbox, the values for window.event.clientX and clientY seem to be relative to that text instead of the whole window.
Can anyone explain why in this scenario, the values should be relative to the text instead of the whole window?
I guess I can likely find a workaround, but it just really surprised me.
<html>
<body>
window.event.clientX: <br />
<input type="text" id="foo">
<input type="text" value="mouse over me" disabled />
</body>
<script>
function trackMouse() {
document.getElementById('foo').value = window.event.clientX;
}
document.onmousemove = trackMouse;
</script>
</html>
A simple but unsatisfactory explanation is that it is a bug.
Jason Brunette supplies a similar example http://www.excel.net where he describes it thus:
A similar error can be seen when using offsetX. Jan Wolter had this to say regarding the latter in Aug, 2010, at unixpapa.com
He went on to suggest the use of a combination of offsetLeft and possibly multiple offsetParents to get the same effect.