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

123
Views
Multi-Function Button

I am very new to HTML design, and am trying to make a button that when click the first time, changes the text to 'Look, I did something!!!', and that works fine. Then, on the next press, I want to change it back to the original. I was able to successfully do that, but once it was done, it wasn't able to be done again. This was that design.

document.getElementById("button").onclick = function(){
    document.getElementById("button_text").innerHTML = "Look I did something!!!";
    document.getElementById("button").innerHTML = "Go Back";
    document.getElementById("button").onclick = function(){
        document.getElementById("button_text").innerHTML = "Click Me. I'm a button!!!";
        document.getElementById("button").innerHTML = "Click Me";
    }
}

Can somebody please help me with this, as I really have no idea how to make this work.

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

0

A simple way to toggle a button's text:

let active = false;

document.getElementById("button").onclick = () => {
  // "Toggle" the active variable, if false it becomes true, and vice-versa
  active = !active;
  
  // Render different button text based on whether active is true or false
  if(active){
    document.getElementById("button").innerHTML = 'Look I did something!!!';
  }
  else {
     document.getElementById("button").innerHTML = 'Click me';
  }
}
<button id="button">Click me</button>

This is obviously very customizable depending on your needs.

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!