开发者

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


You could try this:

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


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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜