Created
October 4, 2017 15:39
-
-
Save batogov/e10f1068a9a85f5e596a9315e7948a5c to your computer and use it in GitHub Desktop.
Template
This file contains 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
const getElementFromTemplate = (template) => { | |
const container = document.createElement('template'); | |
container.innerHTML = template; | |
// В этом месте функция неявно вернёт DocumentFragment, | |
// который при добавлении в DOM исчезает, а вместо него | |
// вставляются его дети. | |
return container.content; | |
} | |
const templateStr = ` | |
<header class="header"> | |
<h1>Заголовок</h1> | |
</header> | |
<div class="content"> | |
<p>Содержимое</p> | |
</div> | |
`; | |
const root = document.getElementById('root'); | |
const template = getElementFromTemplate(templateStr); | |
root.appendChild(template); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment