Generated SVG image doesn't display

后端 未结 1 1754
终归单人心
终归单人心 2021-01-26 18:44

I\'m developing a JavaScript class to show all SVG objects, but when I create the element \"image\", the browser doesn\'t display it. Though if I copy the generated code and put

相关标签:
1条回答
  • 2021-01-26 19:34

    The problem were the namespaces. This is the correct form to create images dynamically:

    image.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', 'flower.png');
    

    More imformation can be found on MDN's 'Namespaces Crash Course'.

    0 讨论(0)
提交回复
热议问题