Results 1 to 4 of 4

Thread: live load html text

  1. #1
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default live load html text

    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.

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    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:
    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' );

  3. #3
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    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);

  4. #4
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •