var RESPONSE = "<div><span class='foo'>This is a span</span><script>alert('I ran a script');</scr"+"ipt></div>"; var foo = $("#foo"), bar = $("#bar"), bam = $("#bam"); setTimeout(function() { $.ajax({ url:"/echo/html/", type:"POST", data:{html:RESPONSE}, success:function(data) { foo.html(data); } }); },500); setTimeout(function() { bar.load("/echo/html/",{html:RESPONSE},function(data) { console.log(data); }); },1000); setTimeout(function() { bam.load("/echo/html/ div",{html:RESPONSE},function(data) { console.log(data); }); },1500)
Regular $.ajax() <div id="foo"> I am the Foo Div </div> Regular $.fn.load <div id="bar"> I am the Bar Div </div> $.fn.load with Selector <div id="bam"> I am the Bam Div </div>
div { border:1px solid #000; padding:1em; }