how to get mouse x and y in javascript

Solutions on MaxInterview for how to get mouse x and y in javascript by the best coders in the world

showing results for - "how to get mouse x and y in javascript"
Luca
12 Jun 2016
1document.addEventListener("mousemove", () => {
2  let mousex = event.clientX; // Gets Mouse X
3  let mousey = event.clientY; // Gets Mouse Y
4  console.log([mousex, mousey]); // Prints data
5});
6
Michele
20 Apr 2018
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;
Jerónimo
25 May 2019
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>
queries leading to this page
js get mouse position in windowposition of mouse in jshow to tie e client x and y to coordinates in cssjs how to get mouse positionjavascript get pointer position addeventlistenerclientx in javascripttjavascript mouseevent positionposition of the mouse jstrack mouse pointer jshow to get mouse position in jsjavascript how to get mouse x and ymouse coordinates jsmouse x mouse y jsjs get mouse cordsjs event positionjs getmouseposjavascript get position of mousehow to get the correct mouse position in javascriptjavascript mousemove get mouse position get mouse positionget mouse position jsdisplay the mouse x and y coordinates in jsget mouse pos in jsjs mouse coordinates windowjs track mouse positiontypescript get mouse location from eventget mouse event coordinatesevent get mouse positiontracking mouse position javascriptjavascript track mouse movementjavascript find the location of the mousejava scrpt get mouse positionjs get mouse posfind mouse x and y jshjs mouse positionhow to get mouse position javascript htmllog mouse x and y javascriptposition of mouse javascriptget mouse pos in hjavascripthow to get mouse position on a div in javascriptmouse x jsget mouse position of page in javascriptgive clientx and clienty to div in javascripthow to get exact coordinates of mouse click in javascriptjavascript e clientxhow to get the mouse position jsjavascript mouse event get coordinateshow to calculate mouse move y coordinates in javascriptjs get mouse xmouse click x y javascripthow to get cursor coordinates in javascriptjavascript get mouse coordinatesconsole log mouse positionmouse position eventjavascript show mouse coordinateshow to get mouse coordinates on click in javascriptget mouse x y coordinatesget x and y mouse javascriptposition of mouse in html javascriptjavascript mouseover get coordinatesjavascript html get current mouse positionmousemove coordinates javascriptjavascript html mouse coordinatesknow the position of the mouse javascriptget position of mouse with javascriptjs mouse coordinatesget position of element javascripthow to get mouse click position in javascriptjavascript track mouse positionhow to get coordinates of mouse click in javascriptmouse position in javascriptget mouse position from eventprint coordinates in jsget cursor location javascripttrack mouse position x and yhow to get the mouse position in jsjavascript get pointer positionjavascript mouse locationgettin mouse position jsjavascript position cursortooltip positioning event jsevent clientxget x and y mouse position in element javascripthow to get the dom position of mouse in javascriptjavascript get mouse positionhow to get mouse postion with javascriptjavascritp get mouse position relatiev to an elemthow to get the x and y values of the mouse in jshow to get mousemove position in javascripttrack cursor position javascripthow to get mouse x and y in javascriptget position mouse element javascripthow to know coordinate of mouse javascripthow to get the coodernate of the mouse in javascriptconsole mouse x and y on movejs track mousecursor 27s position 28its x and y coordinates 29 jshow to get the mouse position in javascriptmousex jstrack the mouse position with javascriptget mouse position canvasget position of mouse pointer javascripthow to get mouse position in the browser jsjavascript log mouse positionhow to know your pointer coordinates on html pageget mouse coordinates jshow to get mouse position jshow to get mouse coordinates with javascriptjavascript get mouse coordsget position mouse is on the element jsget current mouse location javascripthow to read mouse position jsget mouse click coordinates canvas jsget the current mouse position javascriptjs get mouse position windowcurrent mouse position javascriptget x and y position of mousein javascriptunity get mouse positionget position of cursor javascriptget x y position of mouse javascriptjs get cordinates of the mousehow to get mouse position in java scriptwhat is mouse x and y javascriptevent get mouse coordinateshtml get current mouse positionjavascript get mouse poiter positionjs mouse event get mouse positionget pointer position javascriptcords input javascriptget position of mouse in jstrack mouse position javascripthtml mouse positionjavascript clientxfind point of cursor javascriptjs get mouse position in elementjavascript how to get mouse positionhow to get the cursor pointer position in jsjs shoow pointer coordinates at cursorjavascript detect mouse position javascript mouse positonjavascript show mouse positionget position of mouse javascriptposition mouse javascriptjavascript get mousepositonjs get mouse positionshow mouse pointer location below the pointer in jsjavascript track mouse positionjavascript get exact mouse positionhow can we find the coords of mouse position jsjs detect mouse coordinateshow to have clientx and clienty return coordinates of a particular element jsget mouse position in javascriptdom event javascript clientxget mouse position javascript functionjs get cursor position on documentjs get mouse positoinjs position cursorget mouse loaction in javascripthow to find position of mouse pointer in javascripthow to get the coordinates of the mouse in javascriptfind mouse position javasciptget mouse position on clickjs track mouse locationhow to detect the position of the mouse in javascriptjs get mouse coordinates on moveget mouse coordsget mouse coordinates javascripthow to get mouse location in javascriptjavascript get mouse xyclientx menu manager resetget the mouse x yjs events mouse xhow to get the current mouse position in javascriptget mouse position xclientx jsget cursor position javascriptjavascript mouse positionget page mouse posmouse x y javascripthow to get mouse position in javascriptjavascript get mouse xhtml get pointer positionusing javascript can i get the coordinates of the mouse pointerclientx and clienty in javascriptget cursor position jsmouse event pointer positionjavascript get element with mouseget the mouse position javascripthow to get the cursor pointer coordinates using jsfind location of mouse pointer javascriptclientx javascriptjavascript getting mouse positionget mouse position javascritget mouse current position javascriptget x and y position of mouse javascriptwant to get mouse position in jsget mouse xy jsposition mouse jsjavascript mouse coordinatesget mouse locartion jsjs get element at mouse posmouse position tracking javascripthow to calculate mousemove y coordinates in javascriptjavascript get current mouse positionupdate mouse position javascriptget mouse position htmljavascript mouse x and ylisten to mouse location jsmouse coordinates on clickmouse position on page javascriptget mouse x y coordinates javascriptget mouse coordinateshow to detect mouse position in javascriptget mouse position in jsmouse x mouse y java scriptget user mouse position javascripthow to track mouse movement in javascriptjs get mousexget mouse pos jsjavascript event mousexjs get mouse x yjs get mouse position on click javascript get mouse position on hovercursor position in javascripthow to get current mouse coordinates jsclientx and clienty in jshow to know the mouse place cordinats jsmouse click position javascripthtml canvas get mouse positionevent clientxmouse coordinates in jsjs get mousex and yget coordinates from mouse javascriptget x and y position of mouse in javascriptget mouse x position javascriptget mouse coordinates on clickmouse coordinates in javascripttrack javascript mouse eventget mouse position element javascriptevent mousexjs get mouse position x 2cyjavascritpt get mouse positionhow to get x y coord of mouse jsjs mouse x and yget mouse position function javascriptmouse coordinates javascriptjs detect mouse positionvanilla js get cursor positionget current mouse position in javascripthow to check mouse coordinates jshow to get mouse in javascriptjavascript get x y mousejavascript get x position of mousehow to get current mouse position in javascripthow to get the mouse position using javascriptcapture x and y coordinates of mousejavascript get cursor x y positionget mouse coordinates in jsget mouse coordinate jsjs mouse move get cursor coordinatesjavascript current mouse positionhow to get mouseposition javascriptget javasccript mousejavascript track mouse pointerget live coordinates of mouse with javascriptmouse position js livemouse position jsdocument js get mouse positionget mouse position javascript on mouse movejavascript show current mouse positionjavascript get cursor positionget x and y of mouse on screen jsjs mouse xget where mouse is on page javascriptjs get mouse movementget coordinates of mouse click javascriptclientx property javascriptjavascript get mouse x y positionget mouse coordinates in javascriptselenium get mouse coordinates pythonget position of mouse codehs jsclientx in javascriptjavascript calculate mouse movementjavascript event target coordinatesget pointer position on pagewindow get mouse positionjs mousemove get mouse positionhow to print mouse position in javascriptjavascript track mouse pointeconsole log position of mouse pointer in javascriptjs getting mouse coords returning objectget mouse click coordinates javascriptget x y mouse jsmouse in mouse out javascriptjs document ouse positionget mouse position how to find mouse coordinates in javascriptevent clientx propertiesjs get mouse coordinateshow to get mouse xy xoordinates in jsjavascript get mouse x and yget x and y of the mouse jsjs mouse coordinates window get mouse pointer position in javascriptget element mouse position javascriptjavascript to show x y coordinates of mousejavascript get mouse position changeposition of mouse jsget element by mouse position javascriptreturn mouse position javasctipfind mouse position javascriptjava script get mouse coordinateshow to get mouse position javascriptget mouse x jsshow x and y coordinates of mouse javascriptjavascript mouse positon listenerevent target coordinates htmljavascript get position of mouse on pageconsole log mouse positionhow to make track the position of the mouse in javascripttake mouse position javascriptmouse x y jsmouse x position javascriptevent clientx javascriptget current mouse coordinates javascriptget mousex in jswrite text on cursor click using javascript event clientxget mouse position javasxcriptget mouse pos in javascripthow to get the position of the mouse in javascripthow to get mouse position jsavascirptmouse offset javascriptshow mouse position on canvas jsmouse position javascriptget mouse cursor position javascriptget mouse location from event javascripthow to find mouse position in javascriptget current x and y value of mouse javascriptjs log click locationcheck mouse position javascriptjavascript position of cursorget mouse location jsget position cursor javascriptget mouse yget exact mouse position javascripthow to set mouse position in javascriptjavascript get mouse locationjs mouse pointer positionjs get current mouse positiongetmouseposition 28event 29 function javascriptget mouse location javascriptjavascrip current mouse positionjs get position of mousegetting mouse position javascriptgetmouseposition 28event 29 javascriptget mouse pointer coords jsget pointer positionclient x and y in reacthow to display mouse coordinates in javascriptgett mouse position jsjavascript get current mouse position clickjs x and y of mousehow to get mouse pointer position in javascriptclientx of element in jsjavascript get current mouse locationget mouse position javascriptget position of mouse in button jsjavascript get poision x mousehow to get mouse cursor coordinate using jshow to get the mouse position in js 3fjs get mouse datamouse x and yhow to get current mouse location jsget mouse x and y on a div javascriptjs get mouse postitionhow to get the coordinates of mouse in jsjs mouse event get mouse coordinateshow to track mouse position in jswindow mouse position jstrack mouse pointer javascriptjavascript listen mouse positionhow to see mouse position javascriptcalculate the position of mouse on x axis javascriptjavascript get mouselocationmouse click coordinates javascripthow to get the mouse coordinates in javascriptjs geting the mouse positionjs get mousejs display mouse coordinatesmouse x 2c y jsjavascript display mouse coordinatespos x and y in javascriptget mouse x and y javascriptmouse event listener javascript mouse coordinatesget mouse input jshow to get position of mouse in javascriptget mouse position javascript relative to elementjavascript get mouse click positionjs mouse event positionget mouse coordinates from eventmouse in and out javascriptjquery clientxhow to set x and y to move mouse in jsjavascript e xyjavascript get mouse coordinatehow to control mouse coordinates in javascriptget y position of mouse javascripthtml get mouse positiondocument get mouse positionget x and y of mouse pos jsmouse current position javascriptmouse pos jsevent x javascriptjs get cursor positionmouse x y coordinates javascript continuouslyget y value of mouse javascripohow to find mouse coordinates js get x and y of mouse javascriptget curser axis in jsjavascript get users mouse positionhow to get mouse coordinates in javascriptjavascript get mouse position on divmouse coordinate in jsjavascript get xy value of mousehtml javascript get mouse positionjs pointer positionmouse position javascript htmljs get pointer positiondetermine mouse coordinates using jsjs get mouse position on mouse moveaccess mouse position javascriptmouse x and y javascriptget mouse x javascriptjs mouse positionjavascript get co ordinates of mouseget mouse position javascript in divhow to get mouse coordinates on jsjavascript get mouse position on pagetrack mouse pointer location jsmouseposition jsjs get mouse coordsjavascript get mouse position on mouse moveget mouse x and y of document javascriptjavascript mouse position on htmls pagetrack mouse jsget mouse positionhow to get mouse information javascriptconsole log mouse position jshtml how to get mouse positionget coordinates from mouse eventhow to find the mouse position in javascriptmouse pointer coordinates jsjavascript how to get mouse x axisjavascript get x and y position of mousejavascript get mouse position in elementgetmouseposition jsjavascript get mouse position w3schoolsfind mouse coordinates jsget position of mouse jshow to get pointer position in javascript 5cjs cursor positionget mouse locationknow mouse location javascriptjs get mouse locationgetmousecoords javascriptget position of mouse eventmousex javascriptjavascript client xjavascript coordinates mousegetmouseposition javascriptgetr mouse position jsmouse cursor position javascriptjs get mouseposget pointer position jscoordinate of mouse htmlevent mouse coordinates javascriptmouse coordinates htmljs client posget mouse position on window javascriptget moiuse position in htmlmouse coordinate javascriptjavascript get mouse positionget current mouse position javascriptget mouse position javascript in a divhow to get access mouse on element in javascriptget coordinates on mouse mvoeget location of mouse javascriptget mouse position on screenmouse x javascriptget position mouse javascripthow to get the coordinate of our mouse in javascripttest mouse y 2fx jsupdate mouse location javascriptjavascript getting the mouse x positionou mouse mouve get positionhow to get mouse position in an elementjavascript get mouse position without eventtrack mouse event javascripthow to get x y mouse position in javascripthow to access clientxjavascript get position mousejavascript get current mouse coordinatesjavascript mouse lockationget mouse position javascript x and y set the mouse position in javascript javascript save mouse positionhow to get mouse coordinates javascripthow to track mouse position in javascriptget mouse postiion javascriptget mouse with jsjavascript mouse x ydetect mouse position javascriptjavascript get mouse posiitonget position of mouse on element jsget mouse position by jsget current position of mouse javascriptjs have position of mouseget mouse position in element javascripthow to get mouse x and y in javascript