I need to know how to write $(function() {...}
in vanilla JS. However, bc it looks like Google doesn't let you search the dollar sign, I can't find it. I do know how to do $(document).ready(function{...}) in vanilla, but how does one do $(function() {...} in vanilla js?
1 Answer
function stuffToDo() { ... }
// If we're already past the "DOM is ready" point, execute immediately:
if (document.readyState === "interactive" || document.readyState === "complete") {
stuffToDo();
}
// Otherwise, wait for DOMContentLoaded to fire:
document.addEventListener("DOMContentLoaded", stuffToDo, { once: true });
-
-
I don't think that justifies downvoting the answer; if you want to downvote the question, go ahead.– DomenicOct 30, 2020 at 20:01
$(element)
? @AviG