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 90 times
-2
![](../../users/profiles/9410179.webp)
AviG
- 350
- 1
- 10
-
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 });
![](../../users/profiles/3191.webp)
Domenic
- 100,627
- 39
- 205
- 257
-
-
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