Ajax replace instead of append

假如想象 提交于 2019-12-29 15:03:32

问题


I used the following jQuery example which works like a charm. However it appends the results. What do I need to change to replace the results instead of appending?


回答1:


you could empty the element before you append

$("#results").empty().append(myHtml);

or use the html method

$("#results").html(myHtml)



回答2:


Just change

$('#results').append(myHtml);

to

$('#results').html(myHtml);



回答3:


ok, last entry 2009, but if the problem still exist:
$("#results").replaceWith(yourContent)




回答4:


Empty function before your append or prepend function.

I tried this & it worked --->

frame is id selector & it append image.

$("#frame").empty().append('<img src="" >' ); 


来源:https://stackoverflow.com/questions/1675215/ajax-replace-instead-of-append

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!