Skip to content

Instantly share code, notes, and snippets.

@dzenzes
Created October 16, 2018 06:21
Show Gist options
  • Save dzenzes/10d9c32cf144f3d8b32e29657e9de3b1 to your computer and use it in GitHub Desktop.
Save dzenzes/10d9c32cf144f3d8b32e29657e9de3b1 to your computer and use it in GitHub Desktop.
if ("content" in document.createElement("template")) {
const features = [
"HTML Template",
"HTML Import",
"Shadow DOM",
"Custom Elements"
];
const template = document.querySelector("#feature"); // (1)
let listItem = template.content.querySelectorAll("li"); // (2)
let list = document.getElementById("webcomponents"); // (3)
features.forEach(feature => {
listItem[0].textContent = feature; // (4)
const clone = document.importNode(template.content, true); // (5)
list.appendChild(clone); // (6)
});
} else {
document.body.appendChild(
document.createTextNode("HTML templates are not supported")
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment