Reputation: 99
Hell i would like to get x , y coordinates into div ID ,at the moment when i click everywhere on the page i get X coords:193,Y coords:53 under the divs i created in HTML.
This is my Code in :
function show_coords(event)
{
var x =event.clientX;
var y=event.clientY;
$("#click").html("X coords: " + x + ", Y coords: " + y);
return false;
}
<body onmousedown="show_coords(event)">
<div id="x">x</div>
<div id="y">y</div>
<div id="click"></div>
</body>
i want x coords:193 to go inside #x and y coords:53 to go inside #y.
Thank You
Upvotes: 1
Views: 438
Reputation: 191729
$("#x").text(x);
$("#y").text(y);
You can just put that before return false
in show_coords
Since you're already using jQuery, instead of doing onmousedown
you can just do:
$("body").on("mousedown", show_coords)
Upvotes: 1