簡體   English   中英

選擇一個標簽並使用jquery更改其文本

[英]select a tag and change its text using jquery

我的DOM結構如下所示。

<div class="selectricWrapper">
  <div class="selectricHideSelect">
    <select name="ageGroup" id="ageGroup">
       <option value="-1">Any</option>
       <option value="0 To 1">0 To 1</option>
       <option value="1 To 2">1 To 2</option>
       <option value="2 To 3">2 To 3</option>
    </select>
  </div>
  <div class="selectric">
    <p class="label">Any</p>
    <b class="button">▾</b>
  </div>
</div>

我可以從選擇器中選擇“ selectric”類

$("#ageGroup").parent().next()

但是如何選擇(選擇器)並更改其子<p>標簽的文本,我不想更改/重寫.button div

任何幫助,將不勝感激,在此先感謝

$("#ageGroup").parent().next().children("p").text("New text");

我認為您正在尋找的是.text()方法:

$('.selectric p.label').text('new text here');

要么:

$('.selectric p:first-child').text('new text here');

http://api.jquery.com/text/

在下面的這種情況下,我們將從頂部DIV轉到所需的DOM對象。

$('.selectricWrapper .selectric p.label').text('Place you text');

要僅更改標簽文本,您需要執行以下操作:

$("#ageGroup").parent().next().children("p.label").text("New text");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM