0

can I change its .svg content, after I loaded an .svg external file using JavaScript image?

const image = new Image();
image.src = 'http://[URL]/image.svg';
image.onload = () => {
    // CHANGE SVG FILE
    // INSERT TO HTML DOM
}

I know about XML HttpRequest but this question is exactly asking on JavaScript Image.

Does the image variable in this case contain the data?

Gunnar Thoreson
  • 313
  • 1
  • 7
Martin Bokša
  • 188
  • 1
  • 1
  • 11
  • 1
    You can find the answer to this question on this other stackoverflow question. https://stackoverflow.com/questions/8102528/how-do-you-access-the-contents-of-an-svg-file-in-an-img-element. – Eli Jun 20 '18 at 11:46
  • Why you need to change the svg file when it loads? This will never end becase changing the src will fire onload again. Actually the order should be the just the opposite: Create object and handler -> attach to document -> catch event. – David Lemon Jun 20 '18 at 11:50
  • @DavidLemon still way to update and save image to another variable. – Martin Bokša Jun 20 '18 at 11:56
  • 1
    @Eli thanks, looks good. – Martin Bokša Jun 20 '18 at 11:56

0 Answers0