I want to add a keydown event listener to the document object without JQuery.
In the listener I’m not accessing the DOM. The only thing I need from the DOM is the document object itself. I only want to disable pressing of certain key.
Is it safe to call it directly in the script (I mean when the script loads), or do I need to use onload callback (or maybe something else)?
Thanks in advance.
The
documentobject is always available wherever you place your script. No need to wait forDOMContentLoadedor anything; just add your listener whenever you like.This is not true for elements within the document.