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

Ben*_*Ben 9 html javascript jquery

我正在临时将内容添加到div,tempDiv,并将其添加到附加到显示的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
  }  
   });
});
Run Code Online (Sandbox Code Playgroud)

我去的时候清除div的临时内容的解决方案?

Ken*_*ler 22

你可以用$("#tempDiv").empty().