Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

559
Vistas
JavaScript for opening images in a new tab

I have a question regarding html and js. I want to make all pictures in <img> tags openable in a new tab without setting up manually a href link for every image. My problem is that I have over 17.000 Pictures on my website and it would be very laborious to do this for every single image. So basically every src link should be set to the href link for the <img> tag.

Is there any possibility to realize that ?

Thank you in advance!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Yeah, haven't tested it (im on mobile) but something like this:

const gallery = document.querySelectorAll(img) 
gallery.forEach(image => {
   let src = image.getAttribute('src')
   image.addEventListener('click', function () {
       window.open(src)
   }
}

Once it's done add img { cursor: pointer } to your css to tell users they can click on it

You'd be better of with a script changing your images to links, and don't forget lazy load

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda