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

551
Views
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 answers
Answer question

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 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!