Pregunta

I load an SVG within an HTML file with the embed element. But now I want to change the color of an gradient within this SVG. In JavaScript there is the contentDocument which I can access to query for the gradient that I am looking for. It appears that the contentDocument is absent fro the embedElement, so how do I do that in Dart?

Here is an example how it can be done in JavaScript: Accessing SVG content in JS

The SVG is embedded like this:

<embed class="emb" src="images/svglogo.svg" width="100" height="100" type="image/svg+xml" />

Karsten

¿Fue útil?

Solución

I found a work-around that avoids the problem. You can simply load the SVG file with a HttpRequest like this:

HttpRequest.getString("../imgs/redLed.svg").then((r)=>svgLED=r);

then insert the String as SvgElement into the DOM like this:

SvgElement svg=new SvgElement.svg(svgLED);
bla.nodes.add(svg);

You can then query the SVG like a normal HTML Element:

svg.query("#lowVal").attributes["stop-color"]=lowOn;
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top