2013-04-12 38 views
1

用下面的HTML代碼:如何更換隻有第一個節點

<ul class="column"> 
    <li><h2>Name</h2></li> 
</ul> 
<ul class="column"> 
    <li><h2>Address</h2></li> 
</ul> 
<ul class="column"> 
    <li><h2>Title</h2></li> 
</ul> 

我怎麼能只更換第一<h2>之間的文本?

我想:

$(".column").first("h2").html("Replacing Name for another name"); 

但這並不作品。

有沒有想法?

+0

你說的 「不工作」 是什麼意思? –

回答

3

你有很多方法來實現這一目標:

$(".column:eq(0) h2").html("Replacing Name for another name"); 

或:

$(".column:first h2").html("Replacing Name for another name"); 
+1

所有的作品!感謝你們!我需要做一些改變才能使這個工作。 '$(「。column:first h2:first」)。html(「my text」);' –

+0

@KleberS。請標記任何答案,如果它解決了您的問題:) – Eli

+1

對不起,我只是在等待接受時間。 –

2

嘗試:

$(".column:first h2").html("Replacing Name for another name"); 
1

嘗試用

$(".column:eq(0) h2").html("Replacing Name for another name"); 

$(".column:first h2").html("Replacing Name for another name"); 

詳情CHECK THIS

相關問題