mousemove() Method - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:mousemove

Description

The mousemove() method triggers the mousemove event, or sets function as mousemove event handler.

Syntax

$(selector).mousemove(function);
Parameter Require Description
function Optional. function to run when the mousemove event is triggered

The following code shows how to get the position of the mouse pointer within a page:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $(document).mousemove(function(event){
        $("span").text(event.pageX + ", " + event.pageY);
    });/*from  w  w w.j  av a 2s.c om*/
});
</script>
</head>
<body>

<p>Mouse is at coordinates: <span></span>.</p>

</body>
</html>

Related Tutorials