0

I am loading an element from another HTML File with the jQuery.load() method.
The element I am loading also has some child nodes, which I am trying to access basically right after the loading call.

Now here's the issue. At the point where I try to access the child elements via document.getElementById() they are not loaded yet, and I just get null/undefined.
Is there any way to delay or wait until everything is loaded in properly? Or some other sort of fix?
Thanks in advance!


**Fun addition:** element.childNodes returns a HTMLCollection with length 1, but childNodes[0] returns undefined (even though there is a value when just printing the Collection)
MrMyth
  • 67
  • 6
  • 1
    `jQuery.load()` expects a callback ([docs](https://api.jquery.com/load/)). That callback function will be executed when the loading has completed. Only then, you can do your `getElementById` – blex Jul 20 '21 at 10:58
  • 2
    You need `$('#container').load(url, null, function () { /* do whatever here */ });` –  Jul 20 '21 at 11:07
  • @ChrisG exactly - I totally misread the Q – Roko C. Buljan Jul 20 '21 at 11:08
  • 1
    Regarding the fun addition: console output of objects is *live*, meaning it will update when the value changes. –  Jul 20 '21 at 11:08

0 Answers0