How can I simulate a click on x
/y
coords on the stats_wrapper
?
<div class="stats_wrapper">
<span class="like_icon"></span>
<span class="number_of_likes">
10
</span>
</div>
How can I simulate a click on x
/y
coords on the stats_wrapper
?
<div class="stats_wrapper">
<span class="like_icon"></span>
<span class="number_of_likes">
10
</span>
</div>
Set the pageX and pageY properties (which are normalized) on the event object and pass it to .trigger(), like this:
var e = new jQuery.Event("click");
e.pageX = 10;
e.pageY = 10;
$("#elem").trigger(e);
Cited form Triggering a JavaScript click() event at specific coordinates
Why would you want to go with X/Y coordinates?
If I were you, I'd use the event dispatcher.
var down = new MouseEvent('mousedown')
var up = new MouseEvent('mouseup');
var elem = document.getElementsByClassName("stats_wrapper")[0];
elem.dispatchEvent(down);
elem.dispatchEvent(up);
That way, you tell your div that it was clicked and you do not need to worry about coordinates. Obviously, I don't know your use case so it might not be what your looking for.
Edit: This is a pure JS solution. For a JQuery solution, you should use $(.stats_wrapper).trigger('click')
as mentionned by Velimir
To simulate a click on .stats_wrapper
you can use this (jQuery):
$(.stats_wrapper).trigger("click");
You can also click any element inside it instead, I see no function of triggering a click on a specific pixel within a single element