Skip to content

Instantly share code, notes, and snippets.

@pomber
Created February 28, 2016 00:54
Show Gist options
  • Save pomber/6027a28f2f42ef5ab9aa to your computer and use it in GitHub Desktop.
Save pomber/6027a28f2f42ef5ab9aa to your computer and use it in GitHub Desktop.
From Zero to Polymer: Step 02 - template
<!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