开发者

How do I clear the text contents of a div in javascript?

开发者 https://www.devze.com 2023-01-03 22:23 出处:网络
I\'m temporarily adding contents to a div,tempDiv, and adding that to a link which is appended to a div, #contentHere, that\'s displayed. I need to clear the contents of tempDiv so that the links aren

I'm temporarily adding contents to a div,tempDiv, and adding that to a link which is appended to a div, #contentHere, that's displayed. I need to clear the contents of tempDiv so that the links aren't appended to each other, creating a string of urls that don't link to anywhere.

$(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 tempD开发者_运维知识库iv here
  }  
   });
});

Solutions to clearing the temporary contents of the div as I go?


You can use $("#tempDiv").empty().

0

精彩评论

暂无评论...
验证码 换一张
取 消