这是类名为“assistance_wrap”的示例 div。
<div class="assistance_wrap">
<div class="top"></div>
<div class="header highlight">Types of assistance offered at this event:</div>
<div class="nearby_header highlight">This event is currently full, but there are other ways you can</div>
</div>
我已经克隆了这个 div,每个克隆版本都附加了一个唯一的 ID。
<div id="assistance_wrap_315" class="assistance_wrap">
<div class="top"></div>
<div class="header highlight">Types of assistance offered at this event:</div>
<div class="nearby_header highlight">This event is currently full, but there are other ways you can</div>
<div id="assistance_wrap_316" class="assistance_wrap">
<div class="top"></div>
<div class="header highlight">Types of assistance offered at this event:</div>
<div class="nearby_header highlight">This event is currently full, but there are other ways you can</div>
在我的 JS 中,我将名称 new_info 分配给类为“assistance_wrap”的示例 div 的副本 并为其分配唯一的 ID 并显示在我的页面上。 现在我想更改类 nearby_header 突出显示 中的文本,谁的父 div id 是 assistance_wrap_316我应该怎么做?
这是我尝试过的。日志的输出基本上是id为assistance_wrap_316的div的整个文本。
console.log(new_info.find('#assistance_wrap_'+ event_data.eventId , '.nearby_header highlight').text());
假设event_data.eventId的值为316
最佳答案
您应该删除","
:
console.log($('#assistance_wrap_'+ event_data.eventId + ' .nearby_header').text());
或使用find()
方法:
console.log($('#assistance_wrap_'+ event_data.eventId).find('.nearby_header').text());
关于javascript - 更改 ID 内的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11531873/