Reteras Remus
Reteras Remus

Reputation: 933

jquery - get mouse coordinates within a function

I can get the coordinates within $(document).ready(function() { $(id).mouemove(function(){}) };

But what if I want to get the coordinates right in a function?

<div id='abc' onmouseover="callFunction(this.id)"></div>

I only get undefined. Why?

function callFunction(arg){
   mouseX = arg.pageX; 
   mouseY = arg.pageY;

   alert('--> ' + mouseX + ' - ' + mouseY);
}

Upvotes: 0

Views: 3716

Answers (1)

Kir
Kir

Reputation: 694

<div id='abc' onmouseover="callFunction(event)">123</div>

function callFunction(e){
console.log(e);
    mouseX = e.clientX;
    mouseY = e.clientY;

    alert('--> ' + mouseX + ' - ' + mouseY);
}

Upvotes: 3

Related Questions