0
let addToDoButton = document.getElementById('addToDo');
let toDoContainer = document.getElementById('toDoContainer');
let inputField = document.getElementById('inputField');

addToDoButton.addEventListener('click', function(){
  var paragraph = document.createElement('p');
  paragraph.innerText = inputField.value;
  toDoContainer.appendChild(paragraph);
})

The event listener isn't working when I click the button

Phil
  • 157,677
  • 23
  • 242
  • 245
Chettos02
  • 1
  • 1
  • 1
    that's true, documents are a browser JS thing... you could get a fake browser for node, or a vdom system, or just build html from strings, depends on what you want to do. – dandavis May 10 '22 at 06:12
  • If you're running this in Node, what is the expected outcome? – Phil May 10 '22 at 06:13
  • I just used node because I didn't really know how else to see what I was doing wrong. I'm following a tutorial and noticed when I pushed the button, nothing was being added and the

    tag doesn't exist

    – Chettos02 May 10 '22 at 06:16
  • I've updated the linked duplicate. See the answers there for why `getElementById()` might not find your elements – Phil May 10 '22 at 06:27
  • Thank you, my problem was that my ID element was misspelled in my index.html in comparison to that of my script.js – Chettos02 May 10 '22 at 06:53

0 Answers0