2012-07-17 97 views
2

这是类名为“assistance_wrap”的样本格。更改ID中的班级

<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与类样品div的副本“assistance_wrap” 并分配唯一的ID,并显示我的网页上。 现在我想改变类里面的文字near_header亮点谁的父母div id是 assistance_wrap_316我应该怎么做?

这是我试过的。日志的输出基本上是div的整个文本,编号为assistance_wrap_316

console.log(new_info.find('#assistance_wrap_'+ event_data.eventId , '.nearby_header highlight').text()); 

假设event_data.eventId的价值为316

+1

如果'new_info'是副本带有'assistance_wrap'类的div然后做'new_info.find('#assistance_wrap _...'试图fin d内部的div – MrOBrian 2012-07-17 22:47:12

回答

2

你应该删除","

console.log($('#assistance_wrap_'+ event_data.eventId + ' .nearby_header').text()); 

或使用find()方法:

console.log($('#assistance_wrap_'+ event_data.eventId).find('.nearby_header').text()); 
+0

控制台的输出是一个空字符串! – 2012-07-17 22:47:20

+0

@YeshwanthVenkatesh对不起,有一个错字,尝试更新的答案。 – undefined 2012-07-17 22:48:41

+1

谢谢它的作品,真的很感激它。 – 2012-07-17 22:49:49