jQuery > Events

Get mouse position in jQuery

How to get the mouse position in jQuery?


To get the mouse position relative to the left and top edge of the page, event.pageX and event.pageY can be used.

<script>
        $("#pEventXEventY").bind("mousemove", function (e) {
            $(this).text("pageX: " + e.pageX + " pageY: " + e.pageY);
        });
    </script>

In the above code, we have attached “mousemove” event in the paragraph whose id is “pEventXEventY”. When user moves mouse on this paragraph, the position of the mouse from left and top edge of the browser window will be written within this paragraph using e.pageX and e.pageY where e is the event argument passed in the declared function.

 Views: 7234 | Post Order: 67



Write for us






Hosting Recommendations