Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sumbad/01d4bc5ec2b01e4a7cd7b85be9fe56b2 to your computer and use it in GitHub Desktop.
Save sumbad/01d4bc5ec2b01e4a7cd7b85be9fe56b2 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>HTML Templates</title>
</head>
<body>
<template id="task">
<li>
<h1>Task name</h1>
<p>Task body</p>
</li>
</template>
<ui id="todo-list"></ui>
<script>
const tasks = [{
name: "Сделать зарядку",
body: "Разминка, пробежка, подтягивание на перекладине"
},
{
name: "Купить продукты",
body: "Хлеб, овощи, чай"
},
{
name: "Подготовить доклад",
body: "Найти проблему, описать суть, найти решение"
}
];
const $template = document.getElementById('task');
const $todoList = document.getElementById('todo-list');
tasks.forEach(task => {
const $clone = document.importNode($template.content, true);
$clone.querySelector('h1').innerText = task.name;
$clone.querySelector('p').innerText = task.body;
$todoList.appendChild($clone);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment