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

153
Views
Dynamic image on page where img src changes based on parameter in url

I was wondering if it was possible to change an image source on a page based on a url parameter? Perhaps using Javascript?

For example, if we have the default image with an ID?

The scenario would be, http://example.com/page-name/?image-id=specifiedimg

and this would load the image as what the source is set for "specifiedimg"

Hoping that makes sense?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can specify the image path in the url and then use URLSearchParams to get the image path and then set the image as source to the image element.

for example: http://example.com/page-name.html?image-id=assets/img/something.png

const searchParams = new URLSearchParams(location.search),
  imagePath = searchParams.get('image-id'),
  image = new Image() // you can use querySelector to target an existing image tag
image.src = imagePath;

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