Skip to content

Instantly share code, notes, and snippets.

@shaunwallace
Created November 12, 2014 13:00
Show Gist options
  • Save shaunwallace/16418f9b255d448d9b34 to your computer and use it in GitHub Desktop.
Save shaunwallace/16418f9b255d448d9b34 to your computer and use it in GitHub Desktop.
Scripting inside HTML imports
// the scripts inside of the import reference it's containing document
var import = document.currentScript.ownerDocument;
// the main document references itself
var doc = document;
// now we can grab things we need from the imported document and clone them into the main document
// here we are grabbing the styles from the imported document and adding them to the main page
var styles = import.querySelector('link[rel="stylesheet"]');
doc.head.appendChild(styles.cloneNode(true));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment