Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

209
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda