简体   繁体   English

选择一个标签并使用jquery更改其文本

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

My DOM structure is like below. 我的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>

I can select class "selectric" from selector 我可以从选择器中选择“ selectric”类

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

but how to select (selector) & change text of its child <p> tag, i don't want to change/rewrite .button div 但是如何选择(选择器)并更改其子<p>标签的文本,我不想更改/重写.button div

any help would be appreciated, thanks in advance 任何帮助,将不胜感激,在此先感谢

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

I think what you're looking for is the .text() method: 我认为您正在寻找的是.text()方法:

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

or: 要么:

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

http://api.jquery.com/text/ 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