Sergey Prostov Sergey Prostov - 10 days ago 8
CSS Question

How can i change the pattern image parameter inside SVG by JavaScript?

i have to change logo inside embedded SVG, logo image link defined in Pattern and applied to Rect/Path container. Is there a way to change link to image (xlink:href="link_to_logo.svg") by JS?

<pattern id="logo"
patternUnits="objectBoundingBox"
x="0" y="0" width="1" height="1">
<image x="0" y="0"
xlink:href="link_to_logo.svg"
width="331" height="331">
</image>
</pattern>

<path id="logo-container" d="M1152 99h331v331h-331z" fill="url(#logo)"/>

Answer
$('#logo img').attr('xlink:href', 'newValue')

should do it.