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

184
Views
Cómo alterar img src onclick usando jQuery o JS

Tengo varias imágenes con URL src que tienen todas

 ....content/..._gal6.jpg?format=100w

¿Cómo puedo usar jQuery o JS para cambiar todas las URL para que terminen con

 ?format=2500w

¿al hacer clic?

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

Como esto

 document.querySelectorAll("img").forEach(img => { const url = new URL(img.src); if (url.searchParams.get("format")) { url.searchParams.set("format", "2500w") console.log(url.toString()) img.src = url.toString() } })
 <img src="bla.jpg?format=250w"> <img src="bla.jpg"> <img src="bla.jpg?format=350w">

about 4 years ago · Santiago Gelvez Report

0

Usando Javascript:

Cambia la propiedad src de la imagen:

 function changeImage(){ document.getElementById('test-image').src = "https://url-to-second-image.com/image.png"; }

Puede llamar a la función usando el evento de clic en el html:

 <img id="test-image" src="the-url/first_image.jpg" onclick="changeImage()">

Aquí hay un jsfiddle: https://jsfiddle.net/f5mwext3/2/

De la misma manera, puede cambiar solo una parte del nombre (estoy usando archivos externos completos por conveniencia)

about 4 years ago · Santiago Gelvez 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!