Reputation: 135
Is there a way to display specific text out of a HTML page which was returned by an ajax call? By specific text, I mean the first paragraph/div of the HTML page returned.
By using $.load in jquery, I am able to fetch the page. How do I proceed from here.
Is it even possible to implement this using jQuery alone, without parsing html at the back end , and returning selected text as the response from my server.
Upvotes: 0
Views: 70
Reputation: 3606
$.load returns the whole html page unless you specify a fragment of it (as seen in another answer here). You might be better off using $.get or $.ajax and then dealing with the returned data using a function:-
E.g. using ajax
$.ajax({
url: "your url here",
success: function(data) {
//Do something with your data (ie the returned html).
}
})
Upvotes: 0
Reputation: 13753
$.get("/mypage.html",function(html){
var fisrtdiv = $('div',$(html)).first();
});
Upvotes: 0
Reputation: 388316
.load() accepts a selector which can be used to specify the fragment of the page to be appended
$('#x').load('page.html div:eq(0)')
Demo: Plunker
Upvotes: 2