You assign variables through the callback function, which is registered in the event handler. This means that when this is done:
$('#var2').html(readOut2);
readOut2 is undefined because it has not yet been set by the mousemove handler function. This handler will not fire until the current code in the queue stops executing and the user moves his mouse. You can define a function in the same scope as variables and call this function from the mousemove handler.
Re: your comments on another answer, you can use a timer:
jQuery(document).ready(function() { var readOut1; var readOut2; $(document).mousemove(function(e) { readOut1 = e.pageX; readOut2 = e.pageY; $('#var1').html(readOut1); }); window.setInterval(function () { $('#var2').html(readOut2); }, 300); });
Andy e
source share