Skip to content

Instantly share code, notes, and snippets.

@DotNetNerd
Created May 22, 2013 08:55
Show Gist options
  • Save DotNetNerd/5626195 to your computer and use it in GitHub Desktop.
Save DotNetNerd/5626195 to your computer and use it in GitHub Desktop.

Revisions

  1. DotNetNerd created this gist May 22, 2013.
    61 changes: 61 additions & 0 deletions ShadowDOM
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,61 @@
    <html>

    <body>

    <template id="nameTagTemplate">
    <style>
    .outer {
    border: 2px solid pink;
    border-radius: 1em;
    font-size: 20pt;
    width: 12em;
    height: 7em;
    text-align: center;
    font-family: sans-serif;
    font-weight: bold;
    background-color: red;
    }
    .name {
    font-size: 45pt;
    font-weight: normal;
    margin-top: 0.8em;
    padding-top: 0.2em;
    background-color: white;
    }
    h5 {
    color:orange; /*Does not show*/
    }
    </style>
    <div class="outer">
    <div class="name">
    <content></content>
    <!--<content select=".first"></content>-->
    </div>
    Weee
    </div>
    </template>

    <style>
    h5 {
    color:blue; /*Does show*/

    }
    .outer {
    background-color: orange; /*Does not show*/
    }
    </style>

    <div id="nameTag">Bob</div>

    <script>
    var shadow = document.querySelector('#nameTag').webkitCreateShadowRoot();
    var template = document.querySelector('#nameTagTemplate');
    shadow.appendChild(template.content);
    template.remove();

    document.querySelector('#nameTag').textContent = "Christian";

    document.querySelector('#nameTag').innerHTML = "<h5>Baah</h5>";
    </script>
    </body>
    </html>