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

188
Visualizações
Get an uncaught Type error at runtime, specifically on toDoContainer.appendChild(paragraph);

I am creating a simple To-Do List to practice deployment. When running my code, I get an error in the console that reads... Uncaught TypeError: Cannot read properties of null (reading 'appendChild') at HTMLButtonElement.

The HTML can be found below

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="/To-Do-List/styles.css">
    <title>To-Do List</title>
</head>
<body> 
    <h1>To-Do List</h1>
    <div class="contianer">
        <input id="inputField" type="text"><button id="addToDo">+</button>
        <div class="toDos" id="toDoContainer>">
        </div>
    </div>
    <script src="/To-Do-List/script.js"></script>
</body>
</html>

This is the JavaScript that runs on the page...

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.classList.add('paragraph-stlying');
    paragraph.innerText = inputField.value;
    toDoContainer.appendChild(paragraph);
    inputField.value = "";
    paragraph.addEventListener('click', function() {
        paragraph.style.textDecoration = "line-through";
    })
    paragraph.addEventListener('dblclick', function() {
        paragraph.removeChild();
    })
})

I am having trouble seeing what is causing this error because I followed along with a tutorial to create this. My code is identical to the video I was watching yet I am unable to yield the same results?

Another issue I have noticed is that when I click the button to add something to the list, a "p" element is not created in the DOM, which is what is expected.

about 4 years ago · Santiago Gelvez
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