I need to run script only when DOM is ready as script does some rewriting of certain attributes of certain tags.
Currently I use document.addEventListener
on DOMContentLoaded
or if not available document.attachEvent
on onreadystatechange
and if both not given I use window.onload
functionality.
I read about defer
tag for scripts that should be executed after document is parsed.
- Does this mean that by setting
defer
attribute I can easily execute my script when DOM is ready? - Is there some hidden stuff I may miss?
- How well is supported i.e. Opera, WebKit, Firefox, IE?
Edit: I'm aware of libraries like JQuery but I can't use them as I need very small script so I need a low level solution.