Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

263
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!