Ajax replace instead of append

JqueryAjaxReplaceAppend

Jquery Problem Overview


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?

Jquery Solutions


Solution 1 - Jquery

you could empty the element before you append

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

or use the html method

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

Solution 2 - Jquery

Just change

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

to

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

Solution 3 - Jquery

ok, last entry 2009, but if the problem still exist:

$("#results").replaceWith(yourContent)

Solution 4 - Jquery

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="" >' ); 

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionshaissView Question on Stackoverflow
Solution 1 - JqueryMarek KarbarzView Answer on Stackoverflow
Solution 2 - JqueryGregView Answer on Stackoverflow
Solution 3 - Jqueryuser8086037View Answer on Stackoverflow
Solution 4 - JqueryNamesh SilvaView Answer on Stackoverflow