Created
February 28, 2016 00:54
-
-
Save pomber/6027a28f2f42ef5ab9aa to your computer and use it in GitHub Desktop.
From Zero to Polymer: Step 02 - 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
<!DOCTYPE html> | |
<html lang="en"> | |
<body> | |
<template id="my-element-template"> | |
<p>My <b>custom element</b> markup!</p> | |
</template> | |
<my-element></my-element> | |
<my-element></my-element> | |
<script> | |
var MyElementProto = Object.create(HTMLElement.prototype); | |
MyElementProto.createdCallback = function() { | |
var t = document.querySelector('#my-element-template'); | |
var clone = document.importNode(t.content, true); | |
this.appendChild(clone); | |
}; | |
var MyElement = document.registerElement( | |
'my-element', { prototype: MyElementProto } | |
); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment