say your page takes time to load and you need to add event handlers through the addEventListener for each element, waiting for the load event might take time making all those displayed buttons unresponsive, so DOMContentLoaded just tells you all the html from the server has been parsed
so if i want add elements with js should i use that?
it is fired before script files and css files are actually parsed, just that html is now ready. inline script will work though
ok, answering your question, yes you can add elements
no i am asking if i want add elements and modify DOMs should i use DOMContentLoaded or not?
Take it this way, inline scripts will work for everything before their tag, DOMContentLoaded just tells you the whole doc has been parsed following the few exceptions outlined in the official documentation
Обсуждают сегодня