Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

206
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!