Jat90
Jat90

Reputation: 663

refreshing DOM after element injection

I can't seem to find the answer to this. Basically, I've used a for-each loop to create several DOM elements and then updated the text using an array.

However, whilst I can see the results in the console, I cannot see them on my webpage. I believe this is because the DOM has not been updated since element creation.

How can I force the DOM to update without refreshing the page?

articles().then(post => {
post.forEach(element => {
const h1 = document.createElement("h1");
const p1 = document.createElement("p");
h1.textContent = element.title;
p1.textContent = element.description;
console.log(h1, p1);
  });
});

Upvotes: 1

Views: 75

Answers (1)

Jat90
Jat90

Reputation: 663

As some comments pointed out, the h1 and p1 had to be appended to the div using the appendChild methods.

Upvotes: 0

Related Questions