Ajax replace instead of append

前端 未结 4 1916
情书的邮戳
情书的邮戳 2020-12-23 14:29

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?

相关标签:
4条回答
  • 2020-12-23 14:57

    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="" >' ); 
    
    0 讨论(0)
  • 2020-12-23 15:01

    you could empty the element before you append

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

    or use the html method

    $("#results").html(myHtml)
    
    0 讨论(0)
  • 2020-12-23 15:10

    Just change

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

    to

    $('#results').html(myHtml);
    
    0 讨论(0)
  • 2020-12-23 15:12

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

    0 讨论(0)
提交回复
热议问题