Skip to content

Instantly share code, notes, and snippets.

@kuwalab
Created March 1, 2014 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuwalab/9286766 to your computer and use it in GitHub Desktop.
Save kuwalab/9286766 to your computer and use it in GitHub Desktop.
<!DOCTYPE html lang="ja">
<html>
<head>
<meta charset="utf-8">
<title>カスタム要素</title>
</head>
<body>
<x-foo></x-foo><br>
<x-foo></x-foo>
<script>
var XFooPrototype = Object.create(HTMLElement.prototype);
XFooPrototype.createdCallback = function() {
this.innerHTML = '<span style="font-weight: bold; color: red;">あいうえお</span>';
};
XFooPrototype.foo = function() {
console.log('foo() called');
};
var XFoo = document.registerElement('x-foo', {
prototype: XFooPrototype
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment