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

77
Views
Change element button to image

I want to ask how to change an element button to an image using javascript when it's clicked? For example, from Submit button to an image of checked.

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

I use svg for demo, you can change it into <img src="https://some_picture">

var button = document.getElementsByTagName("button")[0];

button.addEventListener('click', function() {
  button.innerHTML  =`<svg width="50" height="50"></svg>`
});
<button>click</button>

about 4 years ago · Juan Pablo Isaza Report

0

Add a click event listener to the button that changes its outerHTML property:

btn.addEventListener('click', function(){
  this.outerHTML = `<img src="https://www.gravatar.com/avatar/0fdacb141bca7fa57c392b5f03872176?s=48&d=identicon&r=PG&f=1">`
})
<button id="btn">Click</button>

about 4 years ago · Juan Pablo Isaza Report

0

function myFunction() {
    document.getElementById("contentChange").innerHTML = "Hello World";
}
<button id="contentChange" onclick="myFunction()">Click me</button>

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!