Javascript 如何在SVG文件中添加“appendChild”

Javascript 如何在SVG文件中添加“appendChild”,javascript,Javascript,假设我有arrow.svg文件。在vanilla js中的index.js中,我想appendChild将其添加到主体中。我该怎么做 const theSVGFile = //... read from './arrow.svg' document.getElementById('some-id').appendChild(theSVGFile); 佐伊洛建议的一个例子通常是最简单的方法,但事实是,他应该得到赞扬,因为他击败了我 const daSVGHost=document.create

假设我有
arrow.svg
文件。在vanilla js中的
index.js
中,我想
appendChild
将其添加到主体中。我该怎么做

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

佐伊洛建议的一个例子通常是最简单的方法,但事实是,他应该得到赞扬,因为他击败了我

const daSVGHost=document.createElement(“img”);
daSVGHost.src=”https://i.stack.imgur.com/BVW9D.jpg"; // 这里是SVG
document.getElementById('testeroni').appendChild(daSVGHost)

佐伊洛建议的一个例子,这通常是最简单的方法,但事实是,他应该得到赞扬,因为他比我先做到了

const daSVGHost=document.createElement(“img”);
daSVGHost.src=”https://i.stack.imgur.com/BVW9D.jpg"; // 这里是SVG
document.getElementById('testeroni').appendChild(daSVGHost)

您可以将SVG文件的路径设置为img标记的src。例如:可能重复这项工作您可以在创建SVG元素时附加child您可以将SVG文件的路径设置为img标记的src。示例:创建SVG元素时,可能会重复此工作,您可以附加子项