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

165
Views
How to Amend an image tag in an SVG tag using Javascript?

How would you go about amending an image tag within an SVG using Javascript?

So I have an image stored in a SVG, like so:

<svg height="666px" width="666px" viewBox="0 0 600 600">
 <image id="changingImage" href="phone.png" x="69.0802" y="344.9714" height="28" width="28"></image>
</svg>

So the suggestion I got from online and tried in my script was grabbing the ID and updating the source like so:

document.getElementById("changingImage").src = "phone2.png";

That didn't work, so I thought about it a bit and realized that the image tags in SVG don't use SRC, they use HREF. So I tried the following, but it still didn't work:

document.getElementById("changingImage").href = "phone2.png";

Anyone know how to amend images within an SVG using javascript, or got any ideas about what I could try?

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

0

I'd like to post the answer with the syntax for anyone who might have the same problem. The suggestion from user @enxaneta worked, using setAttribute. Here's the syntax based on the example above.

document.getElementById("changingImage").setAttribute("href", "phone2.png");
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!