Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

mouseevent clientx javascript

<!DOCTYPE html>
<html>
<head>
<style>
div {
  width: 500px;
  height: 300px;
  border: 1px solid black;
  text-align: center;
}
</style>
</head>
<body>

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

</body>
</html>
// https://www.w3schools.com/jsref/event_clientx.asp
Comment

PREVIOUS NEXT
Code Example
Javascript :: react load different .env for local, dev, and prod 
Javascript :: how to change styles when element comes into view 
Javascript :: chack var exist for skip error on javascript 
Javascript :: delete attribute javascript 
Javascript :: what it means --skiptests==true in angular 
Javascript :: p5js class 
Javascript :: node:internal/crypto/hash:67 this[kHandle] = new _Hash(algorithm, xofLen); 
Javascript :: remove item from localstorage 
Javascript :: console.clear js 
Javascript :: video play on page load 
Javascript :: YT.Player is not a constructor 
Javascript :: js do after delay 
Javascript :: sh: 1: nodemon: not found heroku 
Javascript :: how to read a firebase txt file 
Javascript :: how to import jquery file in react js 
Javascript :: redirect not found in react-router-dom 
Javascript :: go to nextelementsibling 
Javascript :: how to make an express server 
Javascript :: debounce in react native hooks 
Javascript :: start peerjs server 
Javascript :: how to exclude a specefic tagname from a javascript query search 
Javascript :: create parent div javascript 
Javascript :: jquery on click dynamic element 
Javascript :: event listener for element lost focus 
Javascript :: geolocation async js 
Javascript :: call a function whenever routerlink is clicke angular 
Javascript :: angular cli add sslkey certificate 
Javascript :: node load file 
Javascript :: shuffling in js 
Javascript :: textbox text change jquery 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =