Instead of copying/pasting the full svg into my index.html file (so that I can access any path for animation), I was wondering if there is a way to load an svg externally AND being able to access any path element? So far, when I load an external SVG file, it gets displayed, but I can't access any specific path. Is there a method/function to accomplish this?
For example, I can change the hexagons' colors with CSS IF the SVG is in the index.html file only. It's not a problem if the SVG is small, but for more intricate SVGs, I'd like to keep them in separate files for clarity.
#hexagon1 {
opacity: 1;
fill: #ffb619;
stroke-width: 4.50001;
stroke-linecap: round;
stroke-miterlimit: 7
}
#hexagon2 {
opacity: 1;
fill: #008000;
stroke-width: 4.50001;
stroke-linecap: round;
stroke-miterlimit: 7
}
<svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" width="101.83981mm" height="74.999893mm"
viewBox="0 0 101.83981 74.999893" version="1.1" id="svg8">
<defs
id="defs2" />
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
id="layer1"
transform="translate(-28.970265,-13.579265)">
<path
id="hexagon1"
d="M 43.906288,64.275181 28.970265,39.449215 43.002172,14.101257 71.9701,13.579265 86.906123,38.405231 72.874217,63.753189 Z" />
<path
id="hexagon2"
d="M 87.810242,88.579156 72.874219,63.753189 86.906125,38.405231 115.87405,37.883239 130.81008,62.709205 116.77817,88.057164 Z" />
</g>
</svg>