2012-07-17 60 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