jQuery.replaceWith doesn't take <script> tags

拈花ヽ惹草 提交于 2019-12-01 07:09:05

This code is from facebook's sample app. Insert <div id="fb-root"></div> in your document. The code requires jQuery to load up the script. In your case, replace //connect...../all.js' with the <script> elements.

(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());

It will return a string!!

$.get("ajax.php")
     .success(function(returningHtmlString) {
          $(element).replaceWith(returningHtmlString);
     });

See jQuery.parseHTML( data [, context ] [, keepScripts ] )

The following should work

var content = jQuery.parseHTML(response, document, true)
$(element).replaceWith(content)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!