我想使用jquery更改第一个div id =“Comment_1”的文本?

时间:2016-07-29 05:05:40

标签: javascript jquery

<div id="Comment_1" class="panel-body">Back when I was in high school
  <div><a href="#">Ajay</a>(725) <span class="sl-date">7/28/2016 2:48:37 PM</span>
  </div>
  <div class="panel-footer">
    <a class="btnDisapproveComment btn btn-outline m-r-10 btn-danger" action="Disapprove" iid="1" href="javascript:void(0)">Disapprove</a>
    <a class="btnEditComment btn btn-outline m-r-10 btn-warning" iid="1" href="javascript:void(0)">Edit</a>
    <a class="btnFlagComment btn btn-outline m-r-10 btn-default " iid="1" href="javascript:void(0)">Flag it</a>
    <a class="btnAllActionComment btn btn-outline m-r-10 btn-info" action="Feature" iid="1" href="javascript:void(0)">Feature it</a>
  </div>
</div>

3 个答案:

答案 0 :(得分:0)

我以为你想要改变&#34;回到我高中时#34;仅

如果有,请添加相同的范围,例如。<span class="span-text-to-replace">Back when I was in high school</span>

然后,

$(".span-text-to-replace").text("My new text");

如果你不想添加任何span / div,你可以这样做,

document.getElementById("Comment_1").childNodes[0].textContent = "My new text"

以上行更改了内容。

希望我回答你的问题!

答案 1 :(得分:0)

  

使用NodechildNodes属性,该属性将返回包括TextNodes

在内的所有子节点

var elem = document.getElementById('Comment_1');
elem.childNodes[0].textContent = "Your Text"
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<div id="Comment_1" class="panel-body">Back when I was in high school
  <div><a href="#">Ajay</a>(725) <span class="sl-date">7/28/2016 2:48:37 PM</span>
  </div>
  <div class="panel-footer">
    <a class="btnDisapproveComment btn btn-outline m-r-10 btn-danger" action="Disapprove" iid="1" href="javascript:void(0)">Disapprove</a>
    <a class="btnEditComment btn btn-outline m-r-10 btn-warning" iid="1" href="javascript:void(0)">Edit</a>
    <a class="btnFlagComment btn btn-outline m-r-10 btn-default " iid="1" href="javascript:void(0)">Flag it</a>
    <a class="btnAllActionComment btn btn-outline m-r-10 btn-info" action="Feature" iid="1" href="javascript:void(0)">Feature it</a>
  </div>
</div>

答案 2 :(得分:0)

如果要更改该div中的文本

,可以执行以下操作
$('#Comment_1').text('I am to lazy to search the www for a simple tutorial on appending a text to a div');