如何`appendChild` SVG文件

时间:2019-07-16 16:56:44

标签: javascript

假设我有arrow.svg文件。在我使用香草JS的index.js中,我想将appendChild设置为正文。我该怎么办?

const theSVGFile = //... read from './arrow.svg'
document.getElementById('some-id').appendChild(theSVGFile);

1 个答案:

答案 0 :(得分:0)

Zoilo建议的一个例子通常是最简单的方法,但现实是他值得称赞,因为他击败了我。

const daSVGHost = document.createElement("img");
daSVGHost.src = "https://i.stack.imgur.com/BVW9D.jpg"; // SVG HERE

document.getElementById('testerooni').appendChild(daSVGHost);
<div id="testerooni"></div>