If I create any draw in SVG, and, instead of putting the code in HTML file, I insert from a JS file (with document.createElement('svg')
), the svg and all its strokes are rendered with 0x0 size.
class Spinner {
constructor(target) {
this.target = document.getElementById(target);
const spinner = document.createElement('svg');
spinner.setAttribute('width', '100');
spinner.setAttribute('height', '100');
const spinnerPath = document.createElement('circle');
spinnerPath.setAttribute('fill', 'red');
spinnerPath.setAttribute('stroke', 'black');
spinnerPath.setAttribute('stroke-width', '3');
spinnerPath.setAttribute('cx', '50');
spinnerPath.setAttribute('cy', '50');
spinnerPath.setAttribute('r', '40');
spinner.append(spinnerPath);
this.target.append(spinner);
}
}
new Spinner('here');
<div id="here"></div>