Or any other tags :)
for eg.
page...
Define: outerHTML function (taken from here)
jQuery.fn.outerHTML = function(s) {
return (s) ? this.before(s).remove() : jQuery("<p>").append(this.eq(0).clone()).html();
}
Then assume your response is stored in data
you can do:
$(data).filter("script").each( function(e) {
// do something with $(e).outerHTML()
} );
Use a regular expression with the pattern <script[^<]*</script>
.
You can try something like:
function getScriptsAsText() {
var div = document.createElement('div');
var scripts = [];
var scriptNodes = document.getElementsByTagName('script');
for (var i=0, iLen=scriptNodes.length; i<iLen; i++) {
div.appendChild(scriptNodes[i].cloneNode(true));
scripts.push(div.innerHTML);
div.removeChild(div.firstChild);
}
return scripts;
}
It returns a array of the current script elements as text, including their start and end tags.
You might also try outerHTML, but it's not that widely supported.