【发布时间】:2013-03-22 22:03:52
【问题描述】:
我正在使用 jQuery 将 class="prettyPhoto" 添加到 <div class="entry-content"> 内部并包含图像的所有链接。
$('.entry-content a').has('img').addClass('prettyPhoto');
代码运行良好;但是我无法调整它以排除位于<div class="hover_link"> 中的任何链接,我不知道如何。
摆弄之后,我得到了以下结果:
if(!$('.entry-content a').parent('.hover_link')) {
$('.entry-content a').has('img').addClass('prettyPhoto');
}
一些示例 html:
<div class="entry-content">
<!-- prettyPhoto should be added to the next link -->
<a href="whatever"><img src="whatever.jpg"></a>
<!-- prettyPhoto shouldn't be added to the next link (there's no img) -->
<a href="whatever">Some Text</a>
<div class="hover_link">
<!-- prettyPhoto shouldn't be added inside of .hover_link -->
<a href="whatever"><img src="whatever.jpg"></a>
</div>
</div>
【问题讨论】:
标签: jquery image parent prettyphoto