Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New event() vs document.createEvent()

Tags:

javascript

what's the difference between those two syntax for creating an event ?

let event = document.createEvent('Event'); 

and

let event = new Event('event');
like image 666
lzaek Avatar asked Sep 21 '25 00:09

lzaek


1 Answers

The first one is the old fashioned way inspired by Java and supported by older browsers like IE.

The second one is the now preferred one and it uses the Event constructor which is supported by all modern browsers.

You can read more here: https://developer.mozilla.org/en-US/docs/Web/Events/Creating_and_triggering_events#the_old-fashioned_way

As stated in the @pilchard comment

like image 194
Alek Avatar answered Sep 22 '25 12:09

Alek