I would like to trigger the MouseEvent manually in typescript and it shows the initEvent is deprecated.
var clickEvent =document.createEvent('MouseEvent');
clickEvent.initEvent('mouseup',true,true);
Is there any alternate way to achieve this?
I would like to trigger the MouseEvent manually in typescript and it shows the initEvent is deprecated.
var clickEvent =document.createEvent('MouseEvent');
clickEvent.initEvent('mouseup',true,true);
Is there any alternate way to achieve this?
initEvent
is now depreciated as shown in the hint. A note in the docs says:
Note: Do not use this method anymore as it is deprecated. Instead use specific event constructors, like Event().
MouseEvent
is an interface and it is used by different types of events. One of them being mouseup
.
The new way of doing this is :
const mouseupEvent = new MouseEvent("mouseup",{bubbles : true, cancelable: true});
// Dispatch the event.
document.dispatchEvent(clickEvent);