i am trying to load in an external html doc into a div then get its html value
is this close?
Code:var imgTxt = $("#target").live("load", function(){ $(this).load('myPage.html'); }); alert(imgTxt);
i am trying to load in an external html doc into a div then get its html value
is this close?
Code:var imgTxt = $("#target").live("load", function(){ $(this).load('myPage.html'); }); alert(imgTxt);
Last edited by ggalan; 12-26-2011 at 11:55 PM.
that will load the entire document into your#targetdiv. 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:Code:/* 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' );
the content inside myPage.html does not have headers and stuff
this is what i ultimately want, but this does not work
Code:$('#target').load('myPage.html'); var imgTxt = $('#target').html(); alert(imgTxt);
got it
Code:$('#target').load('myPage.html',function() { var imgTxt = $(this).html(); alert(imgTxt); });
Bookmarks