Posts Tagged ‘axis’

jQuery: How to get X-axis Y-axis value?

January 31, 2010 |  by Mukesh Chapagain  |  No Comments
0796dea1926d2bceb1fe729dc9579c37 Del.icio.us

Well, it’s terrifically easy to get the x-axis and y-axis value of any point with jQuery. I mean the mouse pointer position. We simply do it with event.pageX and event.pageY.

event.pageX gives the mouse position relative to the left edge of the document. And event.pageY gives the mouse position relative to the top edge of the document.

The following function fetches x and y axis on mousemove over the div content.

$(function(){	
	$("#content").mousemove(function(e){				
		$("#value").html("x-axis: "+e.pageX+"<br />y-axis: "+e.pageY);
	});		
});

View Demo | Download Code