0

I have added a touch start event listener to a image.

Image.addEventListener('touchstart', myFunction);

My question is, is it possible to force a fake touchstart/touchend to occur on my image, without it actually happening? I already know I could simply call the function again whenever I like, I need to actually fake its properties to say a touchend has occurred.

2 Answers 2

1

Check out this answer

You can use fireEvent on IE, and w3c's dispatchEvent on most other browsers. To create the event you want to fire, you can use either createEvent or createEventObject depending on the browser.

Sign up to request clarification or add additional context in comments.

Comments

0

https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Creating_and_triggering_events

var touchStart = new Event('touchstart');
Image.addEventListener('touchstart', myFunction);

Image.dispatchEvent(touchStart);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.