如何在JavaScript中清除div的文本内容?

9
我暂时将内容添加到一个名为tempDiv的div中,然后将该div添加到一个显示的div #contentHere中的链接中。我需要清除tempDiv中的内容,以便链接不会相互附加,从而创建一系列没有链接到任何地方的url。
$(document).ready(function(){
   $.getJSON("data.php", function(data){
     for(i = 0; i < 5; i++){
         $("#tempDiv").append(data.justIn[i].dataLink+ '  ');
         $("#contentHere").append("<a href=\"#tempDiv\">Click to go to the div link</a>");
         //I need to clear the contents of tempDiv here
  }  
   });
});

如何在实时清除 div 的临时内容?
1个回答

23
您可以使用 $("#tempDiv").empty()

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接