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

271
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
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