how to get mouse coordinates in javascript
JavaScript
<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>// 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;
Also in JavaScript:
- Title
- how to manage a db connection in javascript
- Category
- JavaScript
- Title
- How to format a JavaScript date
- Category
- JavaScript
- Title
- average of an array js
- Category
- JavaScript
- Title
- dotenv not loading process.env in node
- Category
- JavaScript
- Title
- angularjs make post request
- Category
- JavaScript
- Title
- find leap year javascript
- Category
- JavaScript
- Title
- como ler um arquivo json com javascript
- Category
- JavaScript
- Title
- add custom marker in react-mapbox-gl
- Category
- JavaScript
- Title
- javascript base64 encode
- Category
- JavaScript
- Title
- how to reset interval javascript
- Category
- JavaScript
- Title
- how to use js console log
- Category
- JavaScript
- Title
- how to remove 000webhost watermark 2019
- Category
- JavaScript
- Title
- ajax .put
- Category
- JavaScript
- Title
- how to generate random string in javascript
- Category
- JavaScript
- Title
- angular http client
- Category
- JavaScript
- Title
- basic javascript
- Category
- JavaScript
- Title
- import reactdom
- Category
- JavaScript
- Title
- how to get today date in javascript
- Category
- JavaScript
- Title
- how to empty form after submit react
- Category
- JavaScript
- Title
- client side redirect javascript
- Category
- JavaScript
- Title
- javascript exercism.io bob solution
- Category
- JavaScript
- Title
- firestore set a document
- Category
- JavaScript
- Title
- form validation react
- Category
- JavaScript
- Title
- how to get a random element of an array javascript
- Category
- JavaScript
- Title
- how to update node.js on linux
- Category
- JavaScript
- Title
- datatable on error.dt
- Category
- JavaScript
- Title
- get current directory vbscript
- Category
- JavaScript
- Title
- create react component class
- Category
- JavaScript
- Title
- find a single element in array of objects javascript
- Category
- JavaScript
- Title
- how to filter object in javascript
- Category
- JavaScript
- Title
- how to get mouse coordinates in javascript
- Category
- JavaScript
- Title
- flutter vs react native
- Category
- JavaScript
- Title
- get the size of the screen javascript
- Category
- JavaScript
- Title
- if object is array javascript
- Category
- JavaScript
- Title
- event.stoppropagation
- Category
- JavaScript
- Title
- iso to date javascript
- Category
- JavaScript
- Title
- angular material theme colors
- Category
- JavaScript
- Title
- how to extract values from array in javascript
- Category
- JavaScript
- Title
- dom is loaded
- Category
- JavaScript
- Title
- how to add set between two date in datatable
- Category
- JavaScript
- Title
- fizzbuzz js
- Category
- JavaScript
- Title
- box shadow javascript style change
- Category
- JavaScript
- Title
- Javascript clear canvas
- Category
- JavaScript
- Title
- edit onclick event
- Category
- JavaScript
- Title
- how to make ajax request javascript
- Category
- JavaScript
- Title
- if str contains jquery
- Category
- JavaScript
- Title
- angular @Output()
- Category
- JavaScript
- Title
- export function javascript
- Category
- JavaScript
- Title
- block comment js
- Category
- JavaScript
- Title
- create a json object in javascript
- Category
- JavaScript
- Title
- how to display image in html from json object
- Category
- JavaScript
- Title
- cache buster in angular application
- Category
- JavaScript
- Title
- express js list all routes
- Category
- JavaScript
- Title
- clear input field javascript
- Category
- JavaScript
- Title
- discord js bot leave voice channel
- Category
- JavaScript
- Title
- convert json to 2d array
- Category
- JavaScript
- Title
- how to load localt ext file in js
- Category
- JavaScript
- Title
- color js
- Category
- JavaScript
- Title
- how to get last string in javascript
- Category
- JavaScript
- Title
- foreach key value javascript
- Category
- JavaScript
- Title
- get browser timezone javascript
- Category
- JavaScript
- Title
- how to move a block in javascript
- Category
- JavaScript
- Title
- async await javascript push
- Category
- JavaScript
- Title
- get query string javascript nodejs
- Category
- JavaScript
- Title
- chart.js label word wrap
- Category
- JavaScript
- Title
- Code is valid JSON equivalent of the key/value pair shown that also preserves the original value: UPC: 043875
- Category
- JavaScript
- Title
- convert boolean to string javascript
- Category
- JavaScript
- Title
- how reliable is js hasownproperty
- Category
- JavaScript
- Title
- delete from array based on value javascript
- Category
- JavaScript
- Title
- icon shwoing a box react native vector icons
- Category
- JavaScript
- Title
- angular attach component to body
- Category
- JavaScript
- Title
- angular stacked bar
- Category
- JavaScript
- Title
- how to use the map method in javascript
- Category
- JavaScript
- Title
- how to add object to array javascript
- Category
- JavaScript
- Title
- angular bootstrap not working
- Category
- JavaScript
- Title
- funcion dentro de objeto
- Category
- JavaScript
- Title
- how to close another browser tab with javascript
- Category
- JavaScript
- Title
- find last item in an array JS
- Category
- JavaScript
- Title
- angular for loop
- Category
- JavaScript
- Title
- ejs current year
- Category
- JavaScript
- Title
- how to compare a string with its ending in javascript
- Category
- JavaScript
- Title
- javascript arrays codeburst
- Category
- JavaScript
- Title
- array.filter in javascript not working in w3schools
- Category
- JavaScript
- Title
- javacript getHTTPURL
- Category
- JavaScript
- Title
- AJAX in reload a div container
- Category
- JavaScript
- Title
- how to clone an object in javascript
- Category
- JavaScript
- Title
- how to attach javascript to html
- Category
- JavaScript
- Title
- boucle foreach js
- Category
- JavaScript
- Title
- api platform vue generator
- Category
- JavaScript
- Title
- express url redirect
- Category
- JavaScript
- Title
- angular http call caching issue even after no-cache
- Category
- JavaScript
- Title
- express json body
- Category
- JavaScript
- Title
- bootstrap 4 form validator with jquery
- Category
- JavaScript
- Title
- expo create react native app
- Category
- JavaScript
- Title
- how to get a toggle button to do different js functions
- Category
- JavaScript
- Title
- how run dockerfile
- Category
- JavaScript
- Title
- add all elements in array javascript
- Category
- JavaScript
- Title
- Expected an assignment or function call and instead saw an expression
- Category
- JavaScript
- Title
- javascript capitalize string
- Category
- JavaScript
- Title
- angular generate component
- Category
- JavaScript