Próbuję utworzyć element SVG w JS, a następnie dołączyć go do DOM. Element SVG odwołuje się jednak do symbolu. Mogę to osiągnąć za pomocą metody insertAdjacentHTML
, ale nie za pomocą metody appendChild
.Skrypty SVG z
Podczas korzystania z appendChild
wszystkie właściwe elementy znajdują się w DOM według inspektorów przeglądarki, ale nie są renderowane poprawnie. Czy ktoś może zrozumieć, dlaczego?
http://codepen.io/bradjohnwoods/pen/dGpqMb?editors=101
<svg display="none">
<symbol id="symbol--circle--ripple" viewBox="0 0 100 100">
<circle cx="50" cy="50" r="25" />
</symbol>
</svg>
<button id="btn">
</button>
<script>
var btn = document.getElementById('btn');
//var myString = '<svg><use xlink:href="#symbol--circle--ripple" width="100" height="100" class="btn--ripple__circle"></use></svg>';
//btn.insertAdjacentHTML('afterbegin', myString);
var svg = document.createElement('svg');
var use = document.createElement('use');
use.setAttribute("xlink:href", "#symbol--circle--ripple");
use.setAttribute("width", "100");
use.setAttribute("height", "100");
use.classList.add("btn--ripple__circle");
svg.appendChild(use);
btn.appendChild(svg);
</script>
'xmlns: xlink = "http://www.w3.org/1999/xlink"' – CoderPi
że nie zrobił nic –