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

86
Views
¿Cómo se cambia el src de una etiqueta de imagen si se hace clic en una etiqueta de botón?

Si tuviera que crear una imagen y darle la fuente de "box.png", usando CSS o Javascript, ¿cómo podría hacer que un botón cambie la fuente de la imagen a "package.png"?

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

0

Al hacer clic en el botón, se cambia el atributo src del elemento <img> en el detector de eventos.

 let button = document.getElementById('toggleButton'); let logo = document.getElementById('logo'); let darkImageURL = "https://cdn-icons-png.flaticon.com/512/196/196685.png"; let lightImageURL = "https://cdn-icons-png.flaticon.com/512/169/169367.png"; button.addEventListener('click', function(event) { if(this.innerHTML === "Dark") { document.body.style.background = "black"; this.innerHTML = "Light"; logo.src = darkImageURL; } else { document.body.style.background = "white"; this.innerHTML = "Dark"; logo.src = lightImageURL; } });
 <body> <button id="toggleButton">Dark</button> <img id="logo" class="nav_logo" src="https://cdn-icons-png.flaticon.com/512/169/169367.png" alt="original logo" width="100" height="100"/> </body>

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!