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

270
Vistas
I want to change background colour when I click input
 <input type="submit" value="Login" onclick="myFunction">

  <!-- Project -->
  <script>
    
    function myFunction(){
      document.getElementById("input[tpye="submit"]").style.backgroundColor="blue";
    }
    
  </script>
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

getElementById gets the element with that id. You're probably looking for querySelector instead, which will select the element that matches that selector:

function myFunction(){ 
    document.querySelector("input[type='submit']").style.backgroundColor="blue";
 }
about 4 years ago · Juan Pablo Isaza Denunciar

0

You have done three mistakes in your code snippet

  1. You have not given () to the function call
  2. You have written incorrect spelling in the querySelector of "type" word
  3. You are calling the getElementById() function but you have not given id to the input box

<input type="submit" value="Login" onclick="myFunction()">

<!-- Project -->
<script>
  
  function myFunction(){
    document.querySelector("input[type='submit']").style.backgroundColor="blue";
  }
  
</script>

about 4 years ago · Juan Pablo Isaza Denunciar

0

In the javascript function you are using 'getElementById' which means that it'll look for the DOM elements with the id you have provided, and the problem is you didn't provided any id.

You have to first give an id to the button

<button id="some_id">Click</button>

And then align your function in this way.

function myFunction(){ document.getElementById("some_id").style.backgroundColor="blue"; }
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