0

I am working on CS50 Web project 3 and I keep getting this error Uncaught (in promise) TypeError: Cannot read properties of null (reading 'appendChild') at new_thing

here is my function

function new_thing(params) {
  let counter = 0;
  let email = params[counter];
  //create new post 
  const post = document.createElement('div');
  post.className = 'post';
  post.innerHTML = `<h3>From: ${email.sender}.</h3> <h1><strong>${email.subject}</strong></h1> <span>${email.timestamp}</span>`;

  //append to DOM
  console.log(post)
  document.querySelector('emails-view').appendChild(post);

}

From what I understand, wrapping the entire function in a document.addEventListener('DOMContentLoaded) would work but when I do that then other functions can't call it.

You must log in to answer this question.

Browse other questions tagged .