event.clientX and event.clientY vs event.x and event.y

coordinates, javascript, performance, var

Solution

I guess event.x/y are defined only in IEs. A quote from IE documentation:

"`event.clientX`: Retrieves the x-coordinate of the mouse cursor relative to the client area of the window, excluding window decorations or scroll bars."

"`event.x`: Retrieves the x-coordinate of the mouse cursor relative to the parent element."

As putvande stated, `clientX` maybe not cross-browser either. `pageX/Y` might be a safer choice.

Problem

When detecting mouse x and y coordinates, is it best to use event.clientX and event.clientY like this: ``` function show_coords(event){ var x=event.clientX; var y=event.clientY; alert("X coords: " + x + ", Y coords: " + y); } ``` or use x and y, like this: ``` function show_coords(event){ var x=event.x; var y=event.y; alert("X coords: " + x + ", Y coords: " + y); } ``` Is one method better/faster than the other? They seem to work identically to me.

Original source