Sergey Prostov Sergey Prostov - 1 year ago 116
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"
x="0" y="0" width="1" height="1">
<image x="0" y="0"
width="331" height="331">

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

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

should do it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download