Manually dispatchEvent DOMContentLoaded

前端 未结 2 1792
难免孤独
难免孤独 2020-12-05 18:47

Is there any way to manually fire the DOMContentLoaded event?

I\'m trying to write a unit-test for some client-side JavaScript which does some stuff on t

2条回答
  •  感情败类
    2020-12-05 19:30

    Since initEvent is deprecated here, it's better to use Event contructor like this:

    window.document.dispatchEvent(new Event("DOMContentLoaded", {
      bubbles: true,
      cancelable: true
    }));
    

提交回复
热议问题