<template> in <svg> can not be handled correctly #3944
Unanswered
lovetingyuan
asked this question in
5. Bugs
Replies: 2 comments 2 replies
-
Line elements are nodes. I'd suspect that since the line element can't actually exist alone, something else is being found first. |
Beta Was this translation helpful? Give feedback.
1 reply
-
Adding this snippet in your code should make template directives work correctly inside of svg elements document.addEventListener("DOMContentLoaded", function() {
var templates = document.querySelectorAll('svg template');
var el, template, attribs, attrib, count, child, content;
for (var i=0; i<templates.length; i++) {
el = templates[i];
template = el.ownerDocument.createElement('template');
el.parentNode.insertBefore(template, el);
attribs = el.attributes;
count = attribs.length;
while (count-- > 0) {
attrib = attribs[count];
template.setAttribute(attrib.name, attrib.value);
el.removeAttribute(attrib.name);
}
el.parentNode.removeChild(el);
content = template.content;
while ((child = el.firstChild)) {
content.appendChild(child);
}
}
}); Adapted from #637 (comment) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Alpine Expression Error: Failed to execute 'importNode' on 'Document': parameter 1 is not of type 'Node'.
Beta Was this translation helpful? Give feedback.
All reactions