PDA

View Full Version : Resolved live load html text



ggalan
12-26-2011, 11:16 PM
i am trying to load in an external html doc into a div then get its html value
is this close?


var imgTxt = $("#target").live("load", function(){
$(this).load('myPage.html');
});

alert(imgTxt);

traq
12-26-2011, 11:30 PM
that will load the entire document into your #target div. If you have a server-side script that returns only the content you want, that's fine; but if you're loading from a regular html page,it will include the doctype, <html> tag, <head> section, etc., which is probably not what you want.

.load() also allows you to specify a document fragment to load, for example:
/* loads only the <body> of the page */
$(this).load( 'myPage.html body' );
/* loads only the contents of the element with id="myElement" */
$(this).load( 'myPage.html #myElement' );

ggalan
12-26-2011, 11:45 PM
the content inside myPage.html does not have headers and stuff
this is what i ultimately want, but this does not work


$('#target').load('myPage.html');
var imgTxt = $('#target').html();
alert(imgTxt);

ggalan
12-26-2011, 11:54 PM
got it


$('#target').load('myPage.html',function() {
var imgTxt = $(this).html();
alert(imgTxt);
});