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

240
Vistas
How can I solve Uncaught TypeError?

While trying to push element in array, I receive an error:

main.js:1 Uncaught TypeError: Cannot read properties of null (reading 'document') at main.js:1:50

Here is my code:

<!DOCTYPE html>
<html>

<body>
  <button id="input">Click Here</button>

  <script>
    const newItem = document.getElementById('.input').document.addEventListener('click', function(addNewItem) {
      let move = ["L", "L", "R", "F", "N"];
      const newMove = move.push('newItem');
      console.log(newMove);
    })
  </script>

</body>

</html>

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

The error is being caused by document.getElementById('.input'). which returns null. There is not .input element, you need to use the correct spelling, like this: 'input'

about 4 years ago · Juan Pablo Isaza Denunciar

0

There are two mistakes in your code.
  1. You are targeting the id by using document.getElementById(".input"), however; id in html is input not .input. You have to remove . before input.
  • Remove document before document.addEventListener
    document.getElementById('input').addEventListener('click', function (arg) 
    {
    
    });
    


I have included a modified example of your code below with the appropriate corrections.

<!DOCTYPE html>
<html>
<body>
    <button id="input">Click Here</button>

    <script>
        const newItem = document.getElementById('input').addEventListener('click', function (addNewItem) {
            let move = ["L", "L", "R", "F", "N"];
            const newMove = move.push('newItem');
            console.log(newMove);
        });
    </script>

</body>
</html>

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