showing results for - "how to get mouse coordinates in javascript"
Maxence
31 Apr 2019
1// Cursor coordinate functions
2var myX, myY, xyOn, myMouseX, myMouseY;
3xyOn = true;
4
5function getXYPosition(e) {
6    myMouseX = (e || event).clientX;
7    myMouseY = (e || event).clientY;
8    if (document.documentElement.scrollTop > 0) {
9        myMouseY = myMouseY + document.documentElement.scrollTop;
10    }
11    if (xyOn) {
12        alert("X is " + myMouseX + "\nY is " + myMouseY);
13    }
14}
15function toggleXY() {
16    xyOn = !xyOn;
17    document.getElementById('xyLink').blur();
18    return false;
19}   
20
21document.onmouseup = getXYPosition;
Philipp
19 Oct 2018
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>
2
3<div onclick="showCoords(event)"><p id="demo"></p></div>
4
5<p><strong>Tip:</strong> Try to click different places in the div.</p>
6
7<script>
8function showCoords(event) {
9  var cX = event.clientX;
10  var sX = event.screenX;
11  var cY = event.clientY;
12  var sY = event.screenY;
13  var coords1 = "client - X: " + cX + ", Y coords: " + cY;
14  var coords2 = "screen - X: " + sX + ", Y coords: " + sY;
15  document.getElementById("demo").innerHTML = coords1 + "<br>" + coords2;
16}
17</script>
Alessandro
13 Jun 2017
1(function() {
2    document.onmousemove = handleMouseMove;
3    function handleMouseMove(event) {
4        var eventDoc, doc, body;
5
6        event = event || window.event; // IE-ism
7
8        // If pageX/Y aren't available and clientX/Y are,
9        // calculate pageX/Y - logic taken from jQuery.
10        // (This is to support old IE)
11        if (event.pageX == null && event.clientX != null) {
12            eventDoc = (event.target && event.target.ownerDocument) || document;
13            doc = eventDoc.documentElement;
14            body = eventDoc.body;
15
16            event.pageX = event.clientX +
17              (doc && doc.scrollLeft || body && body.scrollLeft || 0) -
18              (doc && doc.clientLeft || body && body.clientLeft || 0);
19            event.pageY = event.clientY +
20              (doc && doc.scrollTop  || body && body.scrollTop  || 0) -
21              (doc && doc.clientTop  || body && body.clientTop  || 0 );
22        }
23
24        // Use event.pageX / event.pageY here
25    }
26})();
27
queries leading to this page
mouse position tracking javascriptget mouse positionget cursor location javascriptdom event javascript clientxget user mouse position javascriptjs get mousexjs mouse event get mouse positionget mouse position javascript save mouse positionhow to know coordinate of mouse javascriptjavascript event mousexhow to track mouse position in jscursor 27s position 28its x and y coordinates 29 jsget mouse position in jsget current mouse position in javascriptget position of mouse javascriptjavascript mouse positonhow to find mouse coordinates js typescript get mouse location from eventjs get mouse position in elementcoordinate of mouse htmljavascript html mouse coordinatescurrent mouse position javascriptget position of mouse eventmouse position in javascriptfind mouse position javascriptmouse coordinates jsget mouse event coordinatesget current mouse location javascriptcalculate the position of mouse on x axis javascriptjavascript get mouse coordinateshow to get the coordinates of mouse in jsjavascript get x y mousecapture x and y coordinates of mouseget coordinates of mouse javascriptjavascript position of cursorjavascript get mouse coordinatejavascript get current mouse locationjs how to get mouse positionjavascript getting mouse positionupdate mouse location javascriptjavascript log mouse positionprint mouse coordinates jsmouse location javascripthow to check mouse coordinates jsmousex javascriptget mouse position element javascriptget coordinates from mouse eventhjs mouse positionhow to get pointer position in javascript 5cget mouse pointer coords jsjavascript get mouse position without eventjavascript track mouse positionhow to set x and y to move mouse in jsget mouse x and y javascriptfind mouse possition by jsjs get mouseposjs mouse coordinates windowclientx property javascripthow to get the coordinates of the mouse in the screen in javascriptjavascript e clientxtrack cursor position javascriptmouse pointer coordinates jswindow mouse position jsget mouse position javascript in a divget mouse with jshow to have clientx and clienty return coordinates of a particular element jsmouse event listener javascript mouse coordinatesget mouse position javascript relative to elementhow to get the mouse position htmlget mouse coordinates javascripthtml javascript get mouse positionhow to get mouse location in javascripthow to get position of mouse in javascripthow to get mouse coordinates on jsjs get mouse position on click event clientxjavascript get position of mouseget mouse position javascript in divhow to get mouseposition javascriptjavascript get coordinates of mousejavascript get mouse posiitonknow the position of the mouse javascriptvanilla js get cursor positiontrack mouse jsmouse coordinate javascriptget mouse position javascritjavascript html get current mouse positionhtml canvas get mouse positionjavascript track mouse movementshow mouse position on canvas jsget mouse locartion jshow to get the position of the mouse in javascriptget mouse position in element javascriptgetmouseposition 28event 29 function javascriptmouse x position javascriptget mouse ymouse coordinates javascripthow to get the coordinate of our mouse in javascriptclientx jsget mouse pos in hjavascriptjs get mouse position windowjavascript calculate mouse movementmouse coordinates in jsget mouse position canvasconsole log mouse positiontrack mouse event javascripthow to detect the position of the mouse in javascriptmouse x jsjs get mouse cordshow to get mouse postion with javascriptjavascript get mouse position on pagejavascript get mouse position on hovertrack mouse pointer jsjavascript get mouse position w3schoolshow to get the current mouse position in javascriptget mouse position on screenhow to get the dom position of mouse in javascriptget mouse coordinates jsevent clientx propertiesclient x and y in reacttrack mouse pointer location jsjs have position of mouseget position mouse is on the element jsgetmouseposition javascriptjavascript clientxget mouse position on screen javascriptget mouse position on clickget position cursor javascriptget mouse x position javascriptjavascript mouse x and yjavascript get users mouse positiongive clientx and clienty to div in javascriptjavascript get position mouseget mouse current position javascripthow to get mouse information javascriptmouseposition jsmouse x mouse y java scriptjavascript get co ordinates of mouseget mouse coordinate jsjavascript track mouse pointehow to get the mouse position using javascriptget position of mouse pointer javascriptget mouse position jsjs get mouse positoinposition of mouse javascriptjavascript track mouse pointerget position of element javascriptposition of the mouse jsevent x javascripthow to get mouse x and y in javascriptpos x and y in javascriptwant to get mouse position in jsget x y position of mouse javascripthow to make track the position of the mouse in javascripthow to get mouse pointer position in javascriptjavascript position cursorgettin mouse position jsget x and y position of mouse javascriptget exact mouse position javascriptgetting mouse coordinates javascripthow to get the cursor pointer position in jsjavascript show current mouse positionget mousex in jsget mouse coordinates on clickhow to get coordinates of mouse click in javascriptaccess mouse position javascriptclientx in javascriptjavascript get mouse position in element on mousemoveclientx and clienty in javascripthow can we find the coords of mouse position jsjs geting the mouse positionjavascript mouseevent positionmouse position javascrpitjavascript get mouselocationjavascript get current mouse position clickget mouse position xget the mouse position javascriptjavascritpt get mouse positionjavascript position of mousejavascript current mouse positionmouse position on page javascriptjs event positionjavascript find the location of the mousemouse click coordinates javascriptjs mouse positiontrack mouse position javascriptclientx menu manager resetjs track mousehow to calculate mouse move y coordinates in javascriptmouse position javascript htmljavascript get position of mouse on pagejs document ouse positionconsole log mouse positionjavascrip current mouse positionmouse x javascripthow to get mousemove position in javascriptdocument get mouse positionjavascript get mouse locationjavascript mouse position on htmls pagecords input javascriptjavascript mouseover get coordinatesjs mouse coordinatesis possible to control mouse position jsmouse position js live get mouse positionget the mouse x y coordinates in javascriptevent mousexget mouse coordsget coordinates of mouse click javascripthow to track mouse position in javascripttooltip positioning event jsevent clientxmouse position eventcursor position in javascriptjs cursor positionget mouse pointer position in javascriptselenium get mouse coordinates pythonget mouse loaction in javascripthow to find the mouse position in javascriptjs get mouse x yjs get mouse coordinatesjavascript get mouse position on mouse movehow to get mouse click position in javascriptget mouse position div javascriptgett mouse position jsget mouse coordinates in jsget mouse position by jsget position of cursor javascriptmouse coordinates in javascriptget position of mouse jsgetmouseposition 28event 29 javascriptmouse click position javascriptmouse position javascriptjs detect mouse positionmouse coordinate in jsposition mouse jsjavascritp get mouse position relatiev to an elemtjavascript mousemove get mouse positionmouse cursor position javascripthow to find position of mouse pointer in javascriptdetermine mouse coordinates using jsjavascript get pointer position addeventlistenerjs track mouse positionjavascript get mouse poiter positionposition mouse javascriptwindow get mouse positionget moiuse position in htmlhow to get mouse position jsjs log click locationget mouse x jsget mouse locationhow to get mouse position jsavascirptou mouse mouve get positionjs get cursor positionget mouse x y coordinates javascriptget mouse click coordinates javascriptjs track mouse locationget live coordinates of mouse with javascripthow to get the mouse position in js 3fmouse x and y javascriptjavascript get mouse positionclientx in javascripttjs get current mouse positionhow to access clientxget current mouse position javascriptjavascript get mouse position in divjs events mouse xjavascript how to get mouse positionhow to print mouse position in javascriptjquery clientxlisten to mouse location jscheck mouse position javascriptget pointer position javascriptmouse in and out javascripthow to get mouse position in the browser jsget the current mouse position javascripttake mouse position javascriptjs detect mouse coordinatesjavascript mouse positionget curser axis in jshow to track mouse movement in javascriptget mouse location jsjs get cordinates of the mousejs get mouse postitionset the mouse position in javascript get position of mouse with javascriptget mouse position javasxcripthtml how to get mouse positiontracking mouse position javascripthow to get the cursor pointer coordinates using jshtml get current mouse positionmouse x mouse y jsmouse event pointer positionget mouse pos in javascripttrack javascript mouse eventposition of mouse in html javascriptget element mouse position javascriptmouse current position javascriptjs get pointer positionjavascript get mouse position on divget y position of mouse javascripthow to get mouse position javascriptjs get mouse coordinates on movehow to get mouse in javascriptjs mouse pointer positionhow to get the mouse position in javascriptwrite text on cursor click using javascript event clientxshow x and y coordinates of mouse javascriptget mouse pos in jsconsole mouse x and y on movejava scrpt get mouse positionposition of mouse jsmouse coordinates on clickevent mouse coordinates javascriptjavascript move mouse to coordinatesjs getmouseposmousex jsjavascript e xyjs mouse move get cursor coordinatesjs client posjs position cursorget mouse position of page in javascriptget mouse position in javascriptfind mouse coordinates jsget cursor position jsget position mouse javascriptget x and y of mouse javascripthow to set mouse position in javascripthow to calculate mousemove y coordinates in javascripthow to get mouse position in an elementjs get mouseget position mouse element javascriptjavascript get mouse x and yhow to get the correct mouse position in javascriptclientx of element in jsget current mouse coordinates javascriptjs get mouse position x 2cyget position of mouse in jsjavascript coordinates of mouse inside elementdetect mouse position javascriptmouse x y javascriptget div from mouse position javascriptevent clientx javascriptjs get mouse position in windowget the mouse x ywhat is mouse x and y javascripthow to get current mouse position in javascriptget mouse position htmljavascript get mouse position in elementget mouse x y coordinatesjs get mouse positionjavascript get x position of mousejavascript show mouse coordinatesjavascript get current mouse coordinatesdisplay the mouse x and y coordinates in jshow to tie e client x and y to coordinates in cssjavascript display mouse coordinatesjs display mouse coordinatesposition of mouse in jshow to get mouse cursor coordinate using jsjs mouse xjs pointer positionget mouse coordinatesjavascript get element at mouse positionhow to know your pointer coordinates on html pageget element by mouse position javascriptclientx and clienty in jsget position of mouse in button jsjavascript listen mouse positionjavascript get exact mouse positionmouse offset javascriptjs get mouse datahow to get mouse coordinates on click in javascripthow to control mouse coordinates in javascriptgetr mouse position jshow to get the mouse position in jsjs get mouse movementhow to find mouse position in javascriptjavascript get mouse position changegetting mouse position javascriptget mouse coordinates in javascriptmousemove coordinates javascriptjavascript get cursor positionjavascript get mousepositonjs get mouse coordsget mouse position function javascriptjavascript track mouse positionhow to know the mouse place cordinats jsconsole log position of mouse pointer in javascripthow to find mouse coordinates in javascriptevent get mouse positionget current position of mouse javascriptjs get element at mouse poshow to get mouse coordinates with javascripthow to get mouse coordinates javascriptget mouse location javascriptdocument js get mouse positionhow to get exact coordinates of mouse click in javascriptjavascript how to get mouse x and yget mouse position javascript functionjavascript get element with mousehtml get mouse positionjs mouse event get mouse coordinateshow to display mouse coordinates in javascriptget mouse x javascripthow to get the mouse position jsget mouse location from event javascriptget pointer positionjavascript html get mouse positionjs get cursor position on documenttrack the mouse position with javascripthow to get mouse position on a div in javascripttrack mouse pointer javascriptget current mouse position jsjs mouse event positionprint coordinates in jsget mouse position javascript on mouse movejs getting mouse coords returning objectjava script get mouse coordinatesevent get mouse coordinateshow to get mouse position javascript htmltrack mouse position x and yhow to get the mouse coordinates in javascripthow to get x y mouse position in javascriptupdate mouse position javascriptget position of mouse codehs jsjavascript get current mouse positionmouse pos jsjavascript event target coordinatesjavascript client xfind mouse position javasciptget mouse position javascripthow to get current mouse coordinates jsshow mouse pointer location below the pointer in jshow to read mouse position jsclientx javascriptjavascript get mouse positionhow to get access mouse on element in javascriptget position of mouse on element jsget mouse coordinates from eventget location of mouse javascriptjavascript mouse event get coordinatesknow mouse location javascriptfind location of mouse pointer javascriptget javasccript mouseusing javascript can i get the coordinates of the mouse pointermouse x and yget mouse pos jsget mouse event positionget pointer position on pagegetmousecoords javascriptjs get mouse position on mouse moveget mouse position on window javascriptmouse in mouse out javascriptget cursor position javascriptjavascript show mouse positionunity get mouse positionjs get mouse locationhow to get mouse position in jsjavascript get mouse click positiontest mouse y 2fx jsget mouse position from eventjavascript get pointer positionhow to get mouseposition in javascripthow to get mouse position in javascriptget mouse postiion javascriptjavascript detect mouse position javascript mouse lockationhow to get current mouse location jsmouse coordinates htmlconsole log mouse position jsjs mouse coordinates window get mouse input jshow to detect mouse position in javascriptget mouse click coordinates canvas jsget div mouse position javascriptget mouse position in window javascriptjavascript mouse locationget pointer position jsget coordinates on mouse mvoemouse position jshow to get mouse coordinates in javascripthow to get the coodernate of the mouse in javascriptmouse click x y javascriptjs mousemove get mouse positionget x and y of mouse on screen jsjs get position of mousehow to get cursor coordinates in javascripthow to get mouse xy xoordinates in jsmouse x 2c y jsfind point of cursor javascriptevent target coordinates htmljs get mouse poshow to get the coordinates of the mouse in javascripthow to get mouse coordinates in javascript