<html>
<head>
<title>FML</title>
<script type="text/javascript">
function function1(e, div) {
div.innerHTML="this works"
document.getElementById('myspan').innerHTML= 'x-pos on click: ' + e.clientX
div.addEventListener("mousemove", function(){test(event, this)}, true);
}
function test(e, div) {
div.innerHTML+='<br/>so does this'
//This doesn't work. Can't add event as a parameter to function that has to be executed when using addEventListener
document.getElementById('myspan2').innerHTML= 'y-pos on move: ' + e.clientY
}
</script>
</head>
<body>
<span id="myspan"> </span>
<span id="myspan2"> </span>
<div style="width:100px;height:100px;background-color:blue;overflow:hidden;" onclick="function1(event, this)">
</body>
</html>
Click on the blue div.
I want to add the event mouseover
, have it execute the test()
-function which should contain following parameters: this, event
When the function test(e, div)
is called I keep getting an "event is undefined" error in Firefox and IE, although ironically enough it works perfectly in Chrome and Safari.
Any way I can add the event parameter by using addEventListener
? I can get it to work with window.event
in Chrome and Safari, but this is the exact setup that I want. I've been googling and trial/erroring for a while now, without success... so FML :/ Any tips/hints/... besides shooting myself in the head?
I know jQuery would probably solve all this, but I want to be proficient in Javascript before migrating to jQuery. Or should I migrate anyway?