<svg style="position: absolute;">
<defs>
<pattern id="image" width="1" height="1" viewBox="0 0 100 100">
<image xlink:href='https://upload.wikimedia.org/wikipedia/commons/f/f8/Fulmer_Falls_Closeup_3000px.jpg' width="100" height="100" preserveAspectRatio="none"></image>
</pattern>
</defs>
</svg>
因此,在我的SVG中,我有一个href
链接指向我在互联网上找到的随机图像。我正在尝试更改此链接,因此单击它更改的元素。
JQUERY
var selectedEl = $('#myID li');
selectedEl.on('click', function () {
var mySVG = $('#image');
});
但我不知道如何更新链接。我尝试使用attr
进行更新,但无济于事。
谢谢:)
答案 0 :(得分:1)
考虑到selectedEl
有效,因为缺少html代码,以下应该可以解决问题。 attr
方法应更改任何给定的属性名称。
selectedEl.on('click', function() {
var mySVG = $('#image image');
$(mySVG).attr('xlink:href','the new URL here');
});