Philips
Philips

Reputation: 41

Jquery, append content from url

Is there anyway to append some html content from a file in Jquery?

I know you can use load() in jquery to replace the entire content within an element.

but I wonder if I can conditionally use append('url') to add extra content into an element in Jquery

Upvotes: 4

Views: 10959

Answers (4)

Alan Baylis
Alan Baylis

Reputation: 11

Another way is to do a two step process, i.e

onclick='$("#id1").append("<div id=\"id2\"></div>"); $("#id2").load("content.php");'

This also works to prepend content from another url too.

Upvotes: 0

Vap0r
Vap0r

Reputation: 2616

So you are trying to append dynamic content? Try something like this:

$(document).ready(function(){
  $.get('<URL>', function(data){
    $(<contentelement>).append(<either entire data element, or do some operations on it>);
  });
});

Upvotes: 3

Darin Dimitrov
Darin Dimitrov

Reputation: 1038720

You could try this:

$.get('/someurl', function(result) {
    $('#someElement').append(result);
});

Upvotes: 5

Saeed Neamati
Saeed Neamati

Reputation: 35822

Yes you can. append() literally appends something to the end of an element.

Upvotes: 0

Related Questions