Home >>jQuery Tutorial >jQuery mousemove() Method
jQuery mousemove() method in jQuery is used to attaches a function or triggers the mousemove event to run, when the mouse pointer moves within the selected element.
Syntax:Trigger the mousemove event for the selected elements:
$(selector).mousemove()
Attach a function to the mousemove event:
$(selector).mousemove(function)
Parameter | Description |
---|---|
function | It is an optional parameter and is used to specifies the function to run when the mouse pointer moves event is triggered |
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(document).mousemove(function(event){
$(".mouseMove").text(event.pageX + ", " + event.pageY);
});
});
</script>
</head>
<body>
<p>Mouse is coordinates at: <span class="mouseMove"></span>.</p>
</body>
</html>
Mouse is coordinates at: .