Gowtham Gowtham - 3 months ago 8
HTML Question

addEventListener is not working in plnkr editor while executing script in external file

Here is my first [link][1] where I have used script tag internally and addEventListener is working fine.

Here is my second [link][2] where I have used script externally and addEventListener is not working.

[1]: https://plnkr.co/edit/f8vd7pGijNFxghz56Aze?p=preview
[2]: https://plnkr.co/edit/i1pKKwdSC0O2o3FvhoD4?p=preview

Answer

Move your script to the end of body or add the listerners in window.onload handler.

https://plnkr.co/edit/KvKLCC2QOFdTTEHcmiCl?p=preview https://plnkr.co/edit/6skW5rucm73my9pK6cGw?p=preview