get mouse position javascript

// Cursor coordinate functions
var myX, myY, xyOn, myMouseX, myMouseY;
xyOn = true;

function getXYPosition(e) {
    myMouseX = (e || event).clientX;
    myMouseY = (e || event).clientY;
    if (document.documentElement.scrollTop > 0) {
        myMouseY = myMouseY + document.documentElement.scrollTop;
    }
    if (xyOn) {
        alert("X is " + myMouseX + "\nY is " + myMouseY);
    }
}
function toggleXY() {
    xyOn = !xyOn;
    document.getElementById('xyLink').blur();
    return false;
}   

document.onmouseup = getXYPosition;

3
1

                                    <p>Click in the div element below to get the x (horizontal) and y (vertical) coordinates of the mouse pointer, when it is clicked.</p>

<div onclick="showCoords(event)"><p id="demo"></p></div>

<p><strong>Tip:</strong> Try to click different places in the div.</p>

<script>
function showCoords(event) {
  var cX = event.clientX;
  var sX = event.screenX;
  var cY = event.clientY;
  var sY = event.screenY;
  var coords1 = "client - X: " + cX + ", Y coords: " + cY;
  var coords2 = "screen - X: " + sX + ", Y coords: " + sY;
  document.getElementById("demo").innerHTML = coords1 + "<br>" + coords2;
}
</script>

3 (1 Votes)
0
0
0

                                    (function() {
    document.onmousemove = handleMouseMove;
    function handleMouseMove(event) {
        var eventDoc, doc, body;

        event = event || window.event; // IE-ism

        // If pageX/Y aren't available and clientX/Y are,
        // calculate pageX/Y - logic taken from jQuery.
        // (This is to support old IE)
        if (event.pageX == null && event.clientX != null) {
            eventDoc = (event.target && event.target.ownerDocument) || document;
            doc = eventDoc.documentElement;
            body = eventDoc.body;

            event.pageX = event.clientX +
              (doc && doc.scrollLeft || body && body.scrollLeft || 0) -
              (doc && doc.clientLeft || body && body.clientLeft || 0);
            event.pageY = event.clientY +
              (doc && doc.scrollTop  || body && body.scrollTop  || 0) -
              (doc && doc.clientTop  || body && body.clientTop  || 0 );
        }

        // Use event.pageX / event.pageY here
    }
})();

0
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
how to get current mouse position in javascript how to read mouse position js get mouse position of page in javascript javascript getting mouse position want to get mouse position in js javascript html get current mouse position javascript get element with mouse how to get the position of the mouse in javascript getting mouse position javascript javascript mouse event get coordinates get current mouse position in javascript how to get the coordinates of mouse in js get location of mouse javascript javascritp get mouse position relatiev to an elemt Display the mouse X and Y coordinates in js js mouse event get mouse position position of mouse javascript get mouse postiion javascript get mouse locartion js get mouse location js js get mouse position on mouse move how to get mouse coordinates on click in javascript get current mouse coordinates javascript get mouse x position javascript event mouse coordinates javascript how to get mouse position in an element get mouse current position javascript how to get access mouse on element in javascript mouse position javascrpit get javasccript mouse javascrip current mouse position get mouse position. js get mouse mouse coordinates js js get position of mouse js have position of mouse get mouse position function javascript how to get mouse position on a div in javascript get mouse pos in javascript get mouse pos in hjavascript get mouse coordinates from event get mouse position by js get position of mouse codehs js position of mouse in js js get mouse pos how to get mouse pointer position in javascript js mouse coordinates window js mouse coordinates window. js get mouse position window get mouse position in element javascript javascript get mouse posiiton javascript get mouse position in element get mouse coordinates in javascript mouse location javascript how to get the coordinate of our mouse in javascript mouse coordinates in js javascript current mouse position mouse coordinate javascript mousemove coordinates javascript how to find mouse position in javascript position of mouse js using javascript can i get the coordinates of the mouse pointer get mouse coordinate js javascript get mouse coordinates js get mouse position in window how to get mouse cursor coordinate using js get mouse position in js js geting the mouse position javascript get mouse position on mouse move how to get mouse coordinates on js how to detect the position of the mouse in javascript how to get mouse location in javascript get position of mouse event js mouse event get mouse coordinates java scrpt get mouse position get position of mouse on element js gett mouse position js javascript show mouse position get mouse pos in js get mouse position html get position mouse javascript javascript get mouse position w3schools javascript mouseover get coordinates how to find mouse coordinates in javascript js how to get mouse position get element mouse position javascript how to get coordinates of mouse click in javascript mouse position in javascript javascritpt get mouse position document js get mouse position how to get mouse coordinates with javascript current mouse position javascript get coordinates from mouse event how to get the correct mouse position in javascript js get mouse position on click get mouse with js get mouse position element javascript how to get mouse position jsavascirpt get mouse x y coordinates javascript how to get the mouse position using javascript javascript get exact mouse position js display mouse coordinates find location of mouse pointer javascript javascript get mouse poiter position javascript get current mouse coordinates how to get the mouse position in js? how to check mouse coordinates js javascript get mouse location javascript mousemove get mouse position determine mouse coordinates using js js get mouse coordinates on move position mouse javascript how to find mouse coordinates js get mouse position on window javascript get current position of mouse javascript get element by mouse position javascript get the current mouse position javascript how to get mouse position in the browser js how to get mouse position in js html javascript get mouse position get mouse coordinates in js java script get mouse coordinates window get mouse position document get mouse position track javascript mouse event js get cordinates of the mouse check mouse position javascript get position of element javascript how to get the mouse coordinates in javascript get mouse position in javascript jquery clientx Get mouse coords javascript get position of mouse on page mouse coordinates on click javascript get mouse x and y javascript track mouse position javascript listen mouse position get mouse input js get mouse position on click get mouse position javascrit get mouse position on screen ou mouse mouve get position event.x javascript pos x and y in javascript track mouse pointer location js javascript get mouse position change js get cursor position on document js get cursor position js get mousePos find mouse position javascipt mouse x and y Set the mouse position in Javascript. javascript get co-ordinates of mouse get mouse pointer coords js javascript get mouse position on hover clientx and clienty in javascript how to get mouse position js how to get the mouse position js how to get mouseposition javascript js get mouse position x,y how to set mouse position in javascript javascript get mouselocation write text on cursor click using javascript event.clientx get coordinates on mouse mvoe get mouse x y coordinates javascript position cursor javascript position of cursor javascript how to get mouse x and y how to get mouse information javascript javascript get mouse position mouse in and out javascript get mouse coordinates on click html canvas get mouse position get mouse click coordinates canvas js javascript get mouse position without event window mouse position js get pointer position javascript get cursor position javascript get exact mouse position javascript get mouse x javascript js getMousePos get mouse position canvas show mouse position on canvas js mouse in mouse out javascript know the position of the mouse javascript how to track mouse position in js get x and y position of mouse javascript get position of mouse in button js js event position console mouse x and y on move how to set x and y to move mouse in js get mouse position javascript relative to element how to display mouse coordinates in javascript how to get mouse click position in javascript mouse position on page javascript javascript get x y mouse javascript get mousepositon get live coordinates of mouse with javascript mouse event pointer position what is mouse x and y javascript get mouse x js get position of cursor javascript position of mouse in html javascript get position of mouse in js get moiuse position in html javascript save mouse position javascript get current mouse position click javascript get current mouse position get y position of mouse javascript get mouse position x js get current mouse position javascript e.xy how to get x y mouse position in javascript how to find the mouse position in javascript mouse position event get position cursor javascript print coordinates in js get position of mouse js how to get mousemove position in javascript get x and y of mouse on screen js javascript get position of mouse track mouse position x and y position mouse js javascript get mouse click position event.mouseX get mouse y how to get position of mouse in javascript how can we find the coords of mouse position js how to get the mouse position in js js get mouse location javascript mouseevent position how to print mouse position in javascript mousePosition js javascript get mouse coordinate ClientX Menu Manager reset console.log mouse position js console.log mouse position how to get the coordinates of the mouse in javascript how to get cursor coordinates in javascript how to control mouse coordinates in javascript javascript get users mouse position clientx and clienty in js how to get the dom position of mouse in javascript js get mouse x y tracking mouse position javascript js cursor position javascript calculate mouse movement javascript detect mouse position detect mouse position javascript mouse click position javascript mouse x, y js js get mouse coordinates how to access clientX js events mouse x track mouse pointer javascript track mouse pointer js Javascript track mouse pointe Javascript track mouse pointer get mouse position javasxcript javascript log mouse position get the mouse x y javascript get pointer position addeventlistener show mouse pointer location below the pointer in js getmouseposition javascript hjs mouse position get mousex in js javascript track mouse movement calculate the position of mouse on x axis javascript mouse x mouse y java script mouse x mouse y js event.clientx javascript test mouse y/x js mouse position js live clientx in javascript js mouse event position Get mouse position track mouse event javascript javascript html mouse coordinates js track mouse get mouse position javascript on mouse move console log mouse position get mouse position get mouse location how to get mouse xy xoordinates in js javascript clientx get mouse pos js js document ouse position cursor's position (its X and Y coordinates) js gettin mouse position js javascript mouse positon event.clientX properties how to know the mouse place cordinats js get user mouse position javascript js position cursor get mouse coordinates javascript get mouse coordinates how to get mouse position javascript typescript get mouse location from event track mouse position javascript vanilla js get cursor position getr mouse position js javascript get mouse position on page how to get the cursor pointer coordinates using JS how to get the cursor pointer position in JS js detect mouse coordinates javascript get x position of mouse mouse X y javascript how to get the coodernate of the mouse in javascript javascript mouse position on htmls page js get pointer position html how to get mouse position getmouseposition(event) function javascript getmouseposition(event) javascript update mouse position javascript update mouse location javascript html get current mouse position mouse.x js event get mouse position get position of mouse javascript javascript display mouse coordinates mouse offset javascript js get mouseX get cursor position js clientx in javascriptt JavaScript Mouse X and Y mouse cursor position javascript clientx js mouse x javascript js mouse pointer position js get mouse data mouse coordinates html mouse pos js mouse click coordinates javascript mouse x position javascript js pointer position give clientx and clienty to div in javascript get cursor location javascript get mouse position from event get mouse position javascript function how to have clientX and clientY return coordinates of a particular element js JS get mouse positoin js track mouse position js get mouse coords event.clientx how to get mouse position in javascript get current mouse location javascript how to find position of mouse pointer in javascript mouse coordinates in javascript position of the mouse js how to know your pointer coordinates on html page find mouse position javascript how to detect mouse position in javascript get x y position of mouse javascript javascript mouse lockation mouse coordinates javascript javascript e.clientx console log position of mouse pointer in javascript get mouse click coordinates javascript client x and y in react how to get the mouse position in javascript how to track mouse movement in javascript js log click location JS get mouse cords get mouse loaction in javascript clientx property javascript find point of cursor javascript clientx of element in js mouse x and y javascript how to tie e.client x and y to coordinates in css how to get mouse x and y in javascript get mouse location javascript clientx javascript event target coordinates html get position of mouse pointer javascript get current mouse position javascript get the mouse position javascript javascript client x javascript get pointer position Listen to mouse location js get mouse event coordinates js detect mouse position javascript event target coordinates get pointer position on page get pointer position js tooltip positioning event.jsEvent.clientX javascript get current mouse location js mouse x mouse click x y javascript get mouse x and y javascript js mouse position dom event javascript clientX get mouse location from event javascript html get mouse position javascript get cursor position Cords Input javascript javascript how to get mouse position get position of mouse with javascript javascript get mouse position get mouse coordinates js get pointer position get mouse pointer position in javascript capture x and y coordinates of mouse get x and y of mouse javascript js client pos mousex javascript how to calculate mousemove y coordinates in javascript how to calculate mouse move y coordinates in javascript js get mouse movement cursor position in javascript get curser axis in js selenium get mouse coordinates python unity get mouse position how to get current mouse coordinates js mouseX js coordinate of mouse html javascript event mousex JAVASCRIPT FIND THE LOCATION OF THE MOUSE find mouse coordinates js mouse position js JS track mouse location js get mouse position how to get pointer position in javascript\ js getting mouse coords returning object how to get mouse coordinates in javascript getMouseCoords javascript mouse event listener javascript mouse coordinates javascript mouse position Javascript - Track mouse position mouse position javascript Get mouse position js track cursor position javascript js mouse coordinates get mouse position javascript
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source