Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Script tag with type="text/html" and src="..." loaded, but ignored by jQuery

My page has a tag:

    <script id='header' src='/Templates/Shared/Header.tmpl.html' type='text/html'></script>

Firebug tells me that Firefox 5 is requesting this resource. On the HTML tab, I can navigate to the script element and see that it contains the contents of /Template/Shared/Header.tmpl.html.

jQuery, however, insists that the script tag is empty. $('#header').html() returns an empty string. I don't understand why.

Yes, I can load the file with $.get() and use $('#header').html(data) to set the contents. Then I can use it as I would expect. This obviously generates a second request, which I would like to avoid.

like image 983
Jason Dentler Avatar asked Jul 10 '11 01:07

Jason Dentler


1 Answers

I know this is old, but the answer is simple. The script tag simply does not contain any text or html.

<script id='...' src='...' type='...'></script>

There are no elements or text within the tag. The script will be requested and loaded into memory (if the script type has a handler), but the actual text itself will not be inserted into the DOM.

like image 198
cwharris Avatar answered Sep 28 '22 15:09

cwharris