javascript DOMContentLoaded event listeners

669 views Asked by At

I have several scripts in html document and all of them have one DOMContentLoaded event listener. Will javaScript keep a relative order of listeners executions or execute them synchron?

1

There are 1 answers

0
T.J. Crowder On BEST ANSWER

Yes, if you're using addEventListener. As of DOM3 (several years ago), the order in which addEventListener handlers are called on the same source was defined: It's the order in which they were attached. (And of course, they're executed in series, not parallel, because the main UI script in browsers runs on a single thread. JavaScript isn't single-threaded, not even on browsers, but there's only a single main UI thread; if you want to use other threads, you have to do something on purpose [e.g., web workers and such].)