Ajax replace instead of append

shaiss picture shaiss · Nov 4, 2009 · Viewed 78.8k times · Source

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?

Answer

Marek Karbarz picture Marek Karbarz · Nov 4, 2009

you could empty the element before you append

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

or use the html method

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