0

I'm following a tutorial online on how to make a to do list. found here

I've following it perfectly, but it won't work. Browser states the 'appendChild' is null. The tutorial is 2 years old, is it just script that has been outdated?

Really appreciate the help

function addNewItem() {
    var listItem = document.createElement("li");
    listItem.innerText = "Hello";

    list.appendChild(listItem);
}

var btnNew = document.getElementById("btnAdd");
btnNew.onclick = function() {
    addNewItem(document.getElementById("todoList"));
};

and here's the related part of the html

<p><button id="btnAdd">New Item</button></p>

<ul id="todolist">
</ul>

<script src="todo.js"></script>
2
  • 2
    You need to show your own code, not what you say you've followed "perfectly." Without the code you're actually running, we can't troubleshoot anything for you. FWIW, no, the code in the video is not outdated--it'll work fine. Commented Jun 15, 2014 at 5:11
  • where is list defined? Commented Jun 15, 2014 at 8:07

1 Answer 1

4

You wrote addNewItem and invoked it in a manner which expects that it should take a parameter named list but you never added it as a param in the function definition. This should straighten you up:

function addNewItem(list) {

as opposed to your

function addNewItem() {
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.