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

154
Views
Alternar imagen onclick evento en línea

Administrado con el fragmento a continuación para cambiar de la primera imagen a la segunda imagen usando el evento javascript onclick en línea. Mi pregunta es; ¿Hay alguna forma de volver a cambiar la segunda imagen a la primera al hacer clic en la segunda imagen con otro evento de Javascript en línea? es decir. sin escribir una función.

<img class="first-image" src="/first-image.png" onclick="this.src=\'/second-image.png\'" alt="my images">

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

0

Puedes actualizar tu código así:

 <img class="first-image" src="/first-image.png" onclick="this.src==='/first-image.png' ? this.src='/second-image.png' : this.src='/first-image.png'" alt="my images">

Aquí hay un ejemplo de trabajo:

 <img class="first-image" src="https://photo-works.net/images/europe-landscape-photo-edited.jpg" onclick="this.src==='https://photo-works.net/images/europe-landscape-photo-edited.jpg' ? this.src='https://thumbs.dreamstime.com/b/landscape-nature-mountan-alps-rainbow-76824355.jpg' : this.src='https://photo-works.net/images/europe-landscape-photo-edited.jpg'" alt="my images">

about 4 years ago · Juan Pablo Isaza Report

0

Puede almacenar ambas direcciones URL como propiedades de la etiqueta de imagen, así:

 <img src="/first-image.png" data-src-1="/first-image.png" data-src-2="/second-image.png" onclick="this.src = this.src === this.getAttribute('data-src-1') ? this.getAttribute('data-src-2') : this.getAttribute('data-src-1')" />
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!