It's impossible; the browser does not process the HTML content inside the <script> tags as part of the DOM. When you load the contents of the <script> with $('#idhere').html() , you get the result of the string.
To answer Troy’s question, he most likely includes templates in the <head> his document so that he can ultimately dynamically display content on the browser side. However, if so, the OP should use a different MIME type than text/html . You must use an unknown MIME type, for example text/templates - using text/html confuses the meaning of the target.
I guess the reason you are trying to get into the <script> tag and grab the div because you created small subpatterns within the same <script> tag. These smaller templates should be placed in your <script></script> rather than in the same large <script></script> .
So, instead of:
<script type="text/template" id="big_template"> <div id="sub_template_1"> <span>hello world 1!</span> </div> <div id="sub_template_2"> <span>hello world 2!</span> </div> </script>
Do it:
<script type="text/template" id="template_1"> <span>hello world 1!</span> </script> <script type="text/template" id="template_2"> <span>hello world 2!</span> </script>
source share