-2

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?

AviG
  • 350
  • 1
  • 10

1 Answers1

-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
  • 100,627
  • 39
  • 205
  • 257