Javascript - Track mouse position

<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>

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
tracking mouse position javascript track mouse y position javascript tracking mouse javascript track mouse position js javascript track mouse position Get mouse coords javascript create element on mouse position get current mouse pointer position javascript javascript track live mouse position Javascript - Track mouse position track mouse pointer location js javascript get mouse position change js get mouse Pos Set the mouse position in Javascript. mouse offset html javascript get position on mouse over javascript listener update mouse position javascript get mouse position on hover how to set mouse position in javascript javascript get mouselocation get mouse position in javascript get coordinates on mouse mvoe get mouse x y coordinates window mouse position js get exact mouse position javascript how to get mouse position javascript mouse position in javascript mouse location javascript console mouse x and y on move how to set x and y to move mouse in js get mouse cursor position get mouse x javascript get current mouse position js get mousposition coordinates on ,mouse move html mouse position on page javascript javascript get x y mouse javascript get mousepositon get live coordinates of mouse with javascript how to get the position of your mouse in javascript get position of cursor javascript get position of mouse in js get moiuse position in html javascript save mouse position javascript get current mouse position click get mouse position x how to find the mouse position in javascript even cursor position java script mouse move coordinates get x and y of mouse on screen js js Get mouse coordinates getting mouse position javascript js event mouse position detectmouse position javascript console.log mouse position js how to track mouse position in javascript javascript get users mouse position pointer position javascript javascript how to get the position of the mouse how to get the dom position of mouse in javascript js event positionX position of the coursor js js cursor position javascript calculate mouse movement detect mouse position javascript Javascript track mouse point Javascript track mouse get mouse cursor position javascript how to get the mouse coordinates in javascript js get mouse info get page mouse pos get mousex in js mouse x mouse y js mouse x y coordinates javascript continuously mouse position js live js track mouse get mouse position get mouse location how to get mouse position in javascript js document ouse position html get pointer position get mouse position html html mouse position js position cursor return mouse position javasctip javascript mouse positon listener javascript get pointer position track mouse position javascript vanilla js get cursor position vanilla js get mouse position how to get the cursor pointer position in JS js detect mouse coordinates javascript get x position of mouse get mouse location js 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 location javascript html get current mouse position mouse.x js event get mouse position get position of mouse javascript javascript display mouse coordinates get cursor position js JavaScript Mouse X and Y mouse cursor position javascript mouse x javascript mouse coordinates html mouse pos js mouse x position javascript get mouse position from event get mouse position javascript function javascript cursor position JS get mouse positoin js track mouse position how to get mouse position in javascript how to find position of mouse pointer in javascript mouse coordinates in javascript position of the mouse js find mouse position javascript how to detect mouse position in javascript javascript mouse lockation mouse coordinates javascript how to find mouse position in javascript how to get the mouse position in javascript js log click location JS get mouse cords get mouse loaction in javascript mouse x and y javascript how to get mouse x and y in javascript get position of mouse pointer javascript get the mouse position javascript javascript get current mouse position in % Listen to mouse location js js detect mouse position get pointer position on page get pointer position js get mouse position javascript get current mouse location js mouse x get mouse x and y javascript get mouse location from event javascript get mouse location javascript javascript get cursor position javascript how to get mouse position capture mouse movement javascript get position of mouse with javascript 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 how to calculate mousemove y coordinates in javascript how to calculate mouse move y coordinates in javascript get mouse coordinates mouse position javascript get mouse position js how to get current mouse coordinates js coordinate of mouse html JAVASCRIPT FIND THE LOCATION OF THE MOUSE javascript window mouse position javascript get mouse coordinates js get mouse x position how to get mouse position js js mouse position mouse position js JS track mouse location set mouse position js js get mouse moviment js get mouse position js getting mouse coords returning object get mouse position javascript how to get pointer position in javascript\ how to get mouse coordinates in javascript js get cursor position how to get the position of the mouse in javascript get cursor position javascript javascript get mouse position event.gtcursor javascript mouse event listener javascript mouse coordinates get current mouse position javascript javascript mouse position can I set the mouse location using windows in typescript
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