Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

214
Visualizações
Cannot read properties of 'null' (reading appendChild)

Can anyone tell me what is wrong with my code? This works for all the other elements on the page but not this one, which is the parent to all of them.

let addButton = document.querySelector('.add-note');
addButton.addEventListener('click', (event) => {
  //prevent refresh
  event.preventDefault();
  //note input value
  let noteInput = document.querySelector(".note-input");
  //create note container
  let noteList = document.querySelector(".notes");
  //create note
  let note = document.createElement("li");
  note.classList.add("note");
  noteList.appendChild(note);
});
<div class="title">
  <h1>To Do List</h1>
</div>
<br>
<form>
  <div class="add-note">
    <input class="note-input" type="text" placeholder="Enter to-do item here"></input>
    <button class="add" type="submit">+</button>
  </div>
</form>
<br>
<ul className="notes" id="notes"></ul>

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Is this a React project? className is only available when using React.

<ul className="notes" id="notes"></ul>

change to

<ul class="notes" id="notes"></ul>
about 4 years ago · Juan Pablo Isaza Relatório

0

Your question i a tad unclear, but i think part of it is that you added the event listener to the div instead of the submit button. Change the class in your query selector to ".add" instead of ".add-note".

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda