Find the mouse x, y position with JavaScript using jQuery

This is how you find the mouse x, y position with JavaScript using jQuery:


var _mouseX = 0;
var _mouseY = 0;

jQuery(document).ready(function()
{
	$().mousemove(function(e)
	{
		_mouseX = e.pageX;
		_mouseY = e.pageY;
	});
})

The variables _mouseX and _mouseY will at all times have the updated mouse coordinates.

Published: 14.12.2009
blog comments powered by Disqus