Note that there are some explanatory texts on larger screens.

plurals
  1. POIs " $(document).ready(function () " required for AJAX generated JS?
    primarykey
    data
    text
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. CONo, `$(document).ready` is never *required*, it's just a tool that you can use to cause your code execution to be delayed until the DOM is ready. In your case, you're firing off an ajax request after the dom is ready, meaning your response will also be received after the dom is ready. Therefore, you don't need to wait for the dom to be ready again because you already know it is ready.
      singulars
    2. COpersonally, I'd keep the DOMReady wrapper; make things consistent and uniform so in the event of a non-ajax reference, you're not in trouble. jQuery just fast-forwards DOMReady calls assigned after ready-state anyways, so it's just one additional hope (relatively low overhead all things considered).
      singulars
    3. COThanks for the explanation. What if the AJAX-generated JS needs elements in the AJAX-generated HTML generated from the Ajax itself. In that case would it not be mandatory to have the AJAX JS wait for these elements to be "ready" in the DOM? I have some pretty complicated, relatively speaking, AJAX-generated JS, that .prepends, appends, etc. new elements to the AJAX-generated HTML. It fails consistently unless I use the $(document).ready. I got the fix but I need to understand why. Your explanation helps but some more elaboration on the exact scenario described here will help.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload