jquery load() strips script tags – workaround?

Update now, which you can find on the jQuery doc site:

http://api.jquery.com/load/

It DOES strip tags only if you call load with a specific suffixed selector..

Script Execution

When calling .load() using a URL without a suffixed selector expression, the content is passed to .html() prior to scripts being removed. This executes the script blocks before they are discarded. If .load() is called with a selector expression appended to the URL, however, the scripts are stripped out prior to the DOM being updated, and thus are not executed. An example of both cases can be seen below:

Here, any JavaScript loaded into #a as a part of the document will successfully execute.
1

$('#a').load('article.html');

However, in the following case, script blocks in the document being loaded into #b are stripped out and not executed:
1

$('#b').load('article.html #target');

Leave a Comment