patrick
patrick

Reputation: 657

jquery alternatives to .load

I want to use jQuery to grab a file and load it into a div on a click command. I know that I can do this with load but....

I want to be able to regenerate the same content as many times without clearing the last instance of it. Can anyone recommend another jQuery call to do this?

Upvotes: 1

Views: 1353

Answers (3)

JAAulde
JAAulde

Reputation: 19560

$.fn.getMoreContent = function()
{
    var collection = this;

    $.ajax( {
        url: 'page.html',
        success: function( data )
        {
            collection.append( data );
        }
    } );

    return collection;
};

$( '#someDiv' ).getMoreContent();

Working example: http://jsfiddle.net/JAAulde/dyRjQ/2/

Or:

$( '#someDiv' ).append(
    $( '<div>' ).load( 'page.html' )
);

Working example: http://jsfiddle.net/JAAulde/dyRjQ/3/

Upvotes: 1

Šime Vidas
Šime Vidas

Reputation: 185913

You could load the content into a new element each time:

$('<div>').load('...').appendTo('#container');

Upvotes: 1

OrahSoft
OrahSoft

Reputation: 803

Another way to display external files on web page, is to embed it. You can do something like that:

$("#target embed").attr("src","filename.pdf");

Your HTML should be similar to that:

<div id="target">
   <embed src="" width="500" height="375">
</div>

Upvotes: 0

Related Questions