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?
Asked
Active
Viewed 392 times
-2

AviG
- 362
- 2
- 14
-
do you mean getting to select elements like so? `$(element)`? @AviG – Manuel Abascal Oct 30 '20 at 20:03
1 Answers
-2
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 });

Domenic
- 110,262
- 41
- 219
- 271
-
-
I don't think that justifies downvoting the answer; if you want to downvote the question, go ahead. – Domenic Oct 30 '20 at 20:01