Inside the createdCallbackcontext is this custom-element, not ownerDocument.. You can see this in the console.log(this);inside createdCallback, which logs (from my plunker example ):
<div is="custom-element">
</div>
my-script.js ownerDocument . DOM, DOM HTML. .
var mainDoc = document.currentScript.ownerDocument;
my-script.js (script.js ):
var mainDoc = document.currentScript.ownerDocument;
var CustomElementPrototype = Object.create(HTMLElement.prototype);
CustomElementPrototype.createdCallback = function () {
console.log(this);
var clone = document.importNode(mainDoc.querySelector('#myTemplate').content, true);
this.appendChild(clone);
};
document.registerElement("custom-element", {
prototype: CustomElementPrototype,
extends: 'div'
});
, ( mainDoc):
<html>
<body>
<script src="script.js"></script>
<template id="myTemplate">
hello world
<br>
from template
</template>
</body>
</html>
HTML, :
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<link rel="import" href="custom-element.html">
</head>
<body>
<h1>Hello Plunker!</h1>
<div is="custom-element"></div>
</body>
</html>
https://plnkr.co/edit/jO3ci8vLxolHhvtGxJQ5
:
http://webcomponents.org/articles/introduction-to-html-imports/