I am trying to fire touch events in my javascript to simulate user interaction in order to test functions. I tried the following snippet:
try { var targetElement = document.elementFromPoint(55, 155); console.log(targetElement); var evt = document.createEvent('UIEvent'); evt.initTouchEvent('touchstart', true, true); evt.view = window; evt.altKey = false; evt.ctrlKey = false; evt.shiftKey = false; evt.metaKey = false; targetElement.dispatchEvent(evt); } catch (except){ alert(except); }
The above code throws an exception of 'TypeError: The result of the expression' evt.initTouchEvent [undefined] 'is not a function.'
Can someone point out what I'm doing wrong?
javascript javascript-events
prk Apr 19 2018-11-11T00: 00Z
source share