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

271
Vistas
How to use a function in JavaScript?

I have a function written in JavaScript. The function is correct, I cannot change it. I need to write HTML code to handle it. Unfortunately, I do not fully understand how it works, when starting the debugger it screams errors:

function A2(params) {
  if ((params / (10 % 4)) === 132.993) {
    var m = document.querySelector("Math");
    console.log("A2 hip hip hura");
    m.innerHTML = "Set Text In Here :";
    var arr = [m];
    arr.push("Element");
    arr.push("Second Element");
    m.addEventListener("click", A2(arr));
  }
}
<div id="Math">
  <input type="text" value="nothing" />
</div>

<input type="submit" value="SEND" onclick="A2(265.986)" />

error:
TypeError: Cannot set properties of null (setting 'innerHTML')

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

0

you need to use the querySelector according to the right selector which is # in that case

<html>  
<head>  
<script type = "text/javascript">  
function A2(params) {
    if ((params / (10 % 4)) === 132.993) {
        var m = document.querySelector("#Math");
        console.log(m)
        console.log("A2 hip hip hura");
        m.innerHTML = "Set Text In Here :";
        var arr = [m];
        arr.push("Element");
        arr.push("Second Element");
        m.addEventListener("click", A2(arr));
    }
}
</script>  
</head>  
<body>  
<div id="Math">
    <input type="text" value="nothing" />
</div>

<input type="submit" value="SEND" onclick="A2(265.986)"/>
</body>  
</html> 

about 4 years ago · Juan Pablo Isaza Denunciar

0

What you forgot is just # sign before Math. Use var m = document.querySelector("#Math"); instead of var m = document.querySelector("Math"); In addition, be sure to read these:

Document.querySelector()

CSS Selector Reference

Here, a little example, just run code snippet:

function A2(params) {
    if ((params / (10 % 4)) === 132.993) {
        var m = document.querySelector("#Math");
        console.log("Responding!");
        m.innerHTML = "Button is pressed:";
    }
}
.button {
  background-color: #04AA6D;
  border: none;
  color: white;
  padding: 20px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
}

.button {border-radius: 5px;}
<!DOCTYPE html>
<html>
<head>
<style>
.button {
  background-color: #4CAF50;
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  cursor: pointer;
}
</style>
</head>
<body>

<div id="Math">
    <input type="text" value="nothing" />
</div>

<input type="submit" class="button" value="SEND" onclick="A2(265.986)">

</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