Skip to content

Instantly share code, notes, and snippets.

@benrobot
Last active January 25, 2017 19:46
Show Gist options
  • Save benrobot/a6f306794cb53700080fc6f2cec647dc to your computer and use it in GitHub Desktop.
Save benrobot/a6f306794cb53700080fc6f2cec647dc to your computer and use it in GitHub Desktop.
<!doctype html>
<html>
<body>
<template id="weather-info">
<style>
h2 {
color: red;
}
</style>
<div class="container">
<p>The weather up in:</p>
<h2 class="city-name"></h2>
</div>
</template>
<script>
class WeatherInfo extends HTMLElement {
constructor() {
super()
let tpl = document.currentScript.ownerDocument.getElementById('weather-info')
let content = tpl.content.cloneNode(true)
let shadow = this.attachShadow({mode: 'open'})
shadow.appendChild(content)
}
}
window.customElements.define('weather-info', WeatherInfo)
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment