I am using jquery load to get a div on a different page and insert it into my page. somthing like this:
$('#mydiv').load("/Pages/grid2.aspx" + " #otherpagediv");
In the div on the other page, there is javascript in the div. The javascript is not coming across, only the html content. Is there a way to get everything in the specified div?
This works:
$.get( '/Pages/grid2.aspx', function ( data ) {
$( '#mydiv' ).html( $( '<div></div>' ).html( data ).find( '#otherpagediv' ).clone() );
});
Live demo: http://jsfiddle.net/FRbnD/4/show/light/
To understand the demo, view the source code of both pages that comprise it:
Source code of the demo: http://jsfiddle.net/FRbnD/4/
Source code of the "other page": http://jsfiddle.net/MWkSj/1/
The idea is to retrieve the other page via a $.get
request, and then find the #otherpagediv
and clone it. You then append the clone to the #mydiv
. If you insert a clone to the DOM and if that clone contains a SCRIPT element, that script will be executed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With