Skip to content

Instantly share code, notes, and snippets.

@shigwata
Created November 30, 2016 05:09
Show Gist options
  • Select an option

  • Save shigwata/9d3a2da91e49675c788ba96905fe4599 to your computer and use it in GitHub Desktop.

Select an option

Save shigwata/9d3a2da91e49675c788ba96905fe4599 to your computer and use it in GitHub Desktop.
importsとTemplatesのサンプル
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="import" href="./template.html">
</head>
<body>
<div id="container"></div>
</body>
</html>
<template id="header">
<header>
<p>header</p>
</header>
</template>
<template id="footer">
<footer>
<p>footer</p>
</footer>
</template>
<script>
var me = document.currentScript.ownerDocument;
var header = me.querySelector('#header');
var footer = me.querySelector('#footer');
var container = document.querySelector('#container');
container.appendChild(header.content.cloneNode(true));
container.appendChild(footer.content.cloneNode(true));
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment