这是类名为“ aid_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 分配给带有“aid_wrap”类的示例div的副本 并为其指定唯一ID并显示在我的页面上。 现在我想更改类的内容 nearby_header highlight ,其中父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
答案 0 :(得分:2)
您应该删除","
:
console.log($('#assistance_wrap_'+ event_data.eventId + ' .nearby_header').text());
或使用find()
方法:
console.log($('#assistance_wrap_'+ event_data.eventId).find('.nearby_header').text());