2016-07-29 49 views
-4

我想改變文本的第一個div id =「Comment_1」使用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>

+0

這是什麼? –

+0

該死的,現在看起來不一樣 –

+0

@ArunPJohny - 是什麼讓你這麼想?所有關於經驗的吧! – Rayon

回答

0

我假設你想改變只有「回來時,我在高中的時候」。

如果這樣加跨度相同,等等。,<span class="span-text-to-replace">Back when I was in high school</span>

然後,

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

如果你不想添加任何跨度/每格,你可以這樣做,

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

以上行更改內容。

希望我回答你的問題!

+0

我想改變這個文本 - >當我在高中時回到 –

+0

我的回答適用於你...嘗試讓我知道如果你面對任何問題...只需將文本添加到文本中,並使用$ .text()方法替換內容 – 2016-07-29 05:19:32

+0

我不想使用其他跨度或div .. –

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>

0

你可以做以下的,如果你想改變該div文本

$('#Comment_1').text('I am to lazy to search the www for a simple tutorial on appending a text to a div');