如何在javascript中清除div的文本内容? [英] How do I clear the text contents of a div in javascript?

查看:83
本文介绍了如何在javascript中清除div的文本内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我暂时将内容添加到div,tempDiv,并将其添加到附加到显示的div #contentHere的链接中。我需要清除tempDiv的内容,以便链接不会互相追加,从而创建一串不会链接到任何地方的网址。

$(document).ready(function(){
$ .getJSON(data.php,function(data){
) 5; i ++){
$(#tempDiv)。append(data.justIn [i] .dataLink +'');
$(#contentHere)。append(< a href = \#tempDiv\>点击进入div链接< / a>);
//我需要清除tempDiv的内容
}
} );
});

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


$(#tempDiv)。empty()


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 tempDiv here
  }  
   });
});

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

解决方案

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

这篇关于如何在javascript中清除div的文本内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆