Answer the question
In order to leave comments, you need to log in
How to click on canvas using javascript?
The title says it all. The goal is to click on the hero (more precisely, not a cell, no difference) on the field, googling and trying out 1 single working method, it turned out that it does not work. Here is the code and the game itself:
$('canvas:eq(1)').on("mousedown mouseup", function(e) {
console.log(e.type + " event fired at coords: " + e.pageX + ", " + e.pageY);
});
x_coord = 220;
y_coord = 220;
var e = jQuery.Event( "mousedown", { pageX: x_coord, pageY: y_coord } );
$('canvas:eq(1)').trigger(e);
// execute more code
x_coord = 220;
y_coord = 220;
var e = jQuery.Event( "mouseup", { pageX: x_coord, pageY: y_coord } );
$('canvas:eq(1)').trigger(e);.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question