Created
July 3, 2017 16:53
-
-
Save sumbad/01d4bc5ec2b01e4a7cd7b85be9fe56b2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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