Skip to content

Instantly share code, notes, and snippets.

@pomber
Created February 28, 2016 00:54
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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