3 examples of 'svg appendchild' in JavaScript

Every line of 'svg appendchild' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
10append(el) {
11 if (!(el instanceof GraphSvg)) {
12 el = new GraphSvg(el);
13 }
14 this.node.appendChild(el.node);
15 return el;
16}
301add(element) {
302 this.element.appendChild(element);
303}
6export function addSvg (el, binding, vnode) {
7 let classNames = ['icon']
8 const id = binding.expression || vnode.data.attrs.symbol
9 let svg = el
10
11 // span or svg ?
12 if (vnode.tag === 'span') {
13 // add SVG element
14 svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
15 el.appendChild(svg)
16 }
17
18 // add classes to wrapper
19 classNames.push(`icon--${id}`)
20 classNames.forEach(function (className) {
21 el.classList.add(className)
22 })
23
24 // add title to SVGs
25 const title = document.createElementNS('http://www.w3.org/2000/svg', 'title')
26
27 title.textContent = id
28 svg.appendChild(title)
29
30 // Add the element to
31 const href = `#icon--${id}`
32 const use = document.createElementNS('http://www.w3.org/2000/svg', 'use')
33
34 use.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', href)
35 svg.appendChild(use)
36}

Related snippets