Javascript: Having trouble accessing event handler

So from what I'm been reading from everywhere I checked, this is how I would access a event handler's attributes:

canvas.addEventListener('onmousemove', traceMouse(e));  //Handler gets passed in as 'e'

function traceMouse(e) {   //Then I could just use it like a normal parameter, right?
    mouseX = e.clientX;
    mouseY = e.clientY;
    }

Unfortunately firebug insists that e is not defined. I have absolutely no idea where I went wrong, I probably made some dumb mistake again, and I'm ready to bite my own head off.

Help?

Answers


Actually, in addEventListener , 2nd argument to pass is the name of function which you want to call when event is fired. Now, you are calling the function & passing it e(which is not defined). So, code should be

canvas.addEventListener('mousemove',traceMouse);

And event object will be passed by browser,so you will be able to get clientX & Y.

And in any case you need to pass the argument to function you can use closure. Here is an example. http://jsfiddle.net/parth1403/fVakB/


Need Your Help

Jquery filter on php generated Divs

jquery

I can't seem to figure out why this JQuery isn't filtering. Is my JQuery function not correct or is the php I am using to generate the divs wrong.

Spring Cloud Feign with caching / eTag support

apache-httpclient-4.x etag spring-cloud http-etag netflix-feign

I've been using Spring Cloud Feign and it's great. But I'm noticing that the out-of-the-box behavior doesn't appear to employ client side caching -- such as eTags.