Skip to content

Instantly share code, notes, and snippets.

@jcgregorio
Created March 27, 2018 20:54
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 jcgregorio/b2ef81944bdec8f617c1da87d406a2b8 to your computer and use it in GitHub Desktop.
Save jcgregorio/b2ef81944bdec8f617c1da87d406a2b8 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>select-sk demo</title>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=egde,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript" charset="utf-8">
// This bit of script loads the custom elements v1 polyfill, but only if required.
if (!window.customElements) {
var newScript = document.createElement('script');
newScript.src = "https://cdnjs.cloudflare.com/ajax/libs/custom-elements/1.0.8/custom-elements.min.js";
document.write(newScript.outerHTML);
}
</script>
</head>
<body>
<div></div>
<script type="text/javascript" charset="utf-8">
window.customElements.define('foo-x', class extends HTMLElement {
memberFunc() {
console.log('Inside memberFunc.');
}
});
window.customElements.whenDefined('foo-x').then(() => {
console.log('foo-x defined');
document.querySelector('div').innerHTML = '<foo-x>hello world</foo-x>';
document.querySelector('foo-x').memberFunc();
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment