Created
May 27, 2019 06:14
-
-
Save harmenjanssen/07e425248779c65bc5d11b02fb913274 to your computer and use it in GitHub Desktop.
Wrap JS-dependent elements in a `<template>`, and simply unwrap at runtime.
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> | |
<title>Hello</title> | |
<p>The following search field depends on Javascript, so let's render it with Javascript: | |
<template data-autorender="true"> | |
<form> | |
<input type="search"> | |
</form> | |
</template> |
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
// Run over all templates, and replace them with their contents. | |
document.querySelectorAll('template[data-autorender]').forEach(template => | |
template.parentNode.replaceChild( | |
template.content, | |
template | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment