js

[jQuery] html() 와 append() 차이

hellooooo 2021. 9. 15. 17:19
728x90

jQuery("#id").append(data); : 기존 데이터에 내용이 추가 (쌓이는것)  -> .remove() 필요.

$("#qnaMenuBtn").on("click",function(){
  $.ajax({
    type : "GET",  
    url : "/qna_list.jsp", 
    dataType : "html", 
    success : function(result){
    $(".content").append($(result).find(".qnaListDiv")); 
   }
  });
});

click 할때마다 append 되어 나타나는 모습

jQuery("#id").html(data); : 초기화하고 새로운 내용이 들어간다.  -> .remove() 필요없음

$("#qnaMenuBtn").on("click",function(){
  $.ajax({
    type : "GET",  
    url : "/qna_list.jsp", 
    dataType : "html", 
    success : function(result){
    $(".content").html($(result).find(".qnaListDiv")); 
   }
  });
});

click 할떄마다 초기화