fetch("/text").then(function(response){
response.text().then(function(text){
addWords(text.split(" "))
})
})
words = document.getElementById("parent").children;
I make a GET request using fetch, and then I call a function (addWords(text.split(" "))) which simply just takes an array of text as an arguement and places that text into a div inside a parent div that has an id of "parent".
However, right after, when I attempted to select the children of said parent div, I receive the following error. It seems the issue is that the elements are not loaded into "parent" when I try to grab them.
How can I pause execution, until the text is fully loaded, before trying to grab it?