Question

I would like to create a mouse event manually on an point, knowing its coordinates. I use this function :

$(document.elementFromPoint(x, y)).mousedown();

The click is used by a function that needs the pageX and pageY properties of the event, but it does not work because the created event doesn't have these properties. Does anybody know why?

Thank you!

Was it helpful?

Solution

Simply create a jQuery event with the required properties an pass it over to the "trigger function":

var event = jQuery.Event("mousedown", {pageX: x, pageY: y});
$(document.elementFromPoint(x, y)).trigger(event);

That should work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top