I'm using jQuery's ajax code to load new pages, but wanted him to get only the html of a div.
My codes: HTML:
<body> <div id="content"></div> </body>
Script:
$.ajax({ url:href, type:'GET', success: function(data){ $('#content').html(data); } });
I wanted him to get only the html of $('div#content') on another page. How to do it?
$. ajax({ url:href, type:'GET', success: function(data){ $('#content'). html(data); } });
To replace the entire contents of a page with content from another, you would do this: getHTML( '/about', function (response) { document. documentElement. innerHTML = response.
php", success: function(data){ $. ajax({ url: "data. php? id=data" } });
Ok, You should "construct" the html and find the .content div.
like this:
$.ajax({ url:href, type:'GET', success: function(data){ $('#content').html($(data).find('#content').html()); } });
Simple!
You can use JQuery .load() method:
http://api.jquery.com/load/
$( "#content" ).load( "ajax/test.html div#content" );
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