Select script tags from jQuery get response
When I try to select script tag content from a jQuery get response, I get nothing. I want to insert the content inside the script tag into another div in the dom. This is what I'm trying:
jQuery.get("http://some.url"), function(data) {
var scriptDivs = jQuery(data).find("#scriptdiv");
var scriptOutput = jQuery("#scriptoutput");
jQuery(scriptDivs).each(function(index) {
jQuery(scriptOutput).append(jQuery(this).html());
});
});
I change the script tag to a div and boom, everything works. I know jQuery does weird things with script tags, but all the solutions I've tried after开发者_StackOverflow社区 hours of searching haven't worked. What am I missing?
About getting the content within the -tag. This approach works fine:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script id="myScript">
function hello() {
}
function world() {
}
</script>
<script >
alert($('#myScript').html());
</script>
精彩评论