title: html template tag and jquery
body: <p>I've got this situation where I'm trying to use the <code>&lt;template&gt;</code> tag in my html source:</p>
  
  <pre><code>&lt;template id="some-id"&gt;
    &lt;div id="content-container"&gt;
      &lt;span&gt;{{some_string}}&lt;/span&gt;
    &lt;div&gt;
  &lt;/template&gt;
  </code></pre>
  
  <p>This ends up placing the template in the document but it is not considered to be in the DOM. This means that $("#content-container") is not found in browsers that support template tags. If I search for:</p>
  
  <pre><code>$("#some-id")
  </code></pre>
  
  <p>I get this back:</p>
  
  <pre><code>&lt;template id=​"some-id"&gt;​
    #document-fragment
      &lt;div id="content-container"&gt;
        &lt;span&gt;{{some_string}}&lt;/span&gt;
      &lt;div&gt;
  &lt;/template&gt;​
  </code></pre>
  
  <p>None of this surprises me. What I need to know how to do is to clone the contents of the document-fragment and have a fresh node I can then stick into the DOM where I want it.</p>
  
  <p>I have found examples of how to do this w/o jQuery but much of the code around this stuff is already using jQuery and I need to know how to use jQuery to do this. </p>
  
  <p>My first thought was to get the html and then use it to create a new node:</p>
  
  <pre><code>stuff = $("#some-id").html()
  new_node = $(stuff)
  </code></pre>
  
  <p>This results in the following errors:</p>
  
  <pre><code>Error: Syntax error, unrecognized expression: &lt;the html string&gt;
  </code></pre>
  
  <p>I don't know if the error is caused by the mustache syntax or not. I figure there has to be a jQuery solution to this behavior somewhere but when I search with Google I get craploads of hits for jQuery Templates, which are different.</p>
  
  <p>Does anyone have thoughts, answers or pointers to sites/pages that will help me through this? I'm trying to avoid cobbling together something hackish.</p>
  
  <p>EDIT: I ended up finding this solution (I'm still testing it to make sure it IS a solution but it looks promising);</p>
  
  <pre><code>template = $("#some-id")
  content = template.html()
  new_div = $("&lt;div&gt;&lt;/div&gt;")
  new_div.html(content)
  </code></pre>
  
  <p>I end up with that containing div that I didn't really need previously but I can live with that. But this kind of feels kludgy. Does anyone have a better approach to this? The upside is that it will still work in browsers that haven't adapted the template tag behavior fully yet.</p>
  
  <p>thanks!</p>