You can only get mouse coordinates using mouse events. If you want to capture a mouse position, you can use the mousemove global event mousemove and save the coordinates in a set of variables, to which the focus function may later be available. Example:
var pageX, pageY; //Declare these globally $(window).mousemove(function(e){ pagex = e.pageX; pageY = e.pageY; }); $('input').focus(function(){ console.log(pageX, pageY); // These variables have been defined by the global // mousemove event });
Rob w source share