I’m still new to SVG, so I’m unclear on the terminology.
Is there an SVG only way of passing on a parameter value to use
d element? For example I have hard-coded the text Name in the g
element, but would like to pass it a value from the use
element.
Currently I create the g
element without the text and place some text after I use
it, but there should be a better way.
I have searched widely on the Internet, but I can’t find anything that’s current or relevant to this application.
Some have suggested using JavaScript, but that’s not a general solution, since I won’t be necessarily plugging in to a browser.
<svg width="160" viewBox="0 0 160 120">
<defs>
<g id="test">
<rect width="60" height="40"/>
<text x="8" y="24" stroke="none" fill="black">Name</text>
</g>
</defs>
<use href="#test" x="00" y="20" fill="aqua" stroke="blue"/>
<use href="#test" x="80" y="20" fill="orange" stroke="red"/>
<text y="100">This space for rent</text>
</svg>