【发布时间】:2015-06-03 09:37:05
【问题描述】:
我需要使用 jquery 从多个重复的 HTML 结构中检索媒体 div 上的点击事件的文本信息。
<div class="activity-list">
<div class="media">
<a class="pull-left" href="http://pbs.twimg.com/profile_images/592781386324549633/5QdIRp9T_normal.png">
<img class="media-object" src="http://pbs.twimg.com/profile_images/592781386324549633/5QdIRp9T_normal.png" alt="">
</a>
<div class="media-body">
<a target="_blank" class="pull-left" href="https://twitter.com/Ford Motor Company">
<strong>Ford Motor Company @Ford</strong>
</a>
<br>
<small class="text-muted">06-02-2015 05:53 PM</small>
<small data-original-title="Favorite" data-toggle="tooltip" class="text-muted favorite"><i class="glyphicon glyphicon-star"></i>0</small>
<div class="fb_desc">
"@Barsotta Happy 100,000 miles, Justin! Here's to your next milestone with your truck!"
</div>
</div>
</div>
<div class="media">
<a class="pull-left" href="http://pbs.twimg.com/profile_images/592781386324549633/5QdIRp9T_normal.png">
<img class="media-object" src="http://pbs.twimg.com/profile_images/592781386324549633/5QdIRp9T_normal.png" alt="">
</a>
<div class="media-body">
<a target="_blank" class="pull-left" href="https://twitter.com/Ford Motor Company">
<strong>Ford Motor Company @Ford</strong>
</a>
<br>
<small class="text-muted">06-02-2015 08:37 PM</small>
<small data-original-title="Favorite" data-toggle="tooltip" class="text-muted favorite"><i class="glyphicon glyphicon-star"></i>22</small>
<div class="fb_desc">
"We teamed up with @jonathanadler to create the ultimate road trip u2014 driving directions here: http://t.co/UzE37As167 http://t.co/exDDFJmnGL" </div>
<div class="ista_usr_img">
<a data-rel="prettyPhoto" href="http://pbs.twimg.com/media/CGhAyeXUcAEJjA5.jpg">
<img alt="" class="thumbnail img-responsive" src="http://pbs.twimg.com/media/CGhAyeXUcAEJjA5.jpg">
</a>
</div>
</div>
</div>
</div>
我的 jquery 代码找到点击媒体:
$('.activity-list.media').click(function (e) {
alert('media');
});
但在点击媒体 div 时没有收到任何警报消息。
问题更新:
在 ajax 调用后,所有媒体 div 都设置在活动列表 div 上,因此给定的解决方案对我不起作用。
谢谢 萨米克
【问题讨论】:
-
$('.activity-list .media')在media之间添加一个空格是activity-list的子级
标签: jquery