小编Ale*_*lex的帖子

如果图像父级没有某个类,则jQuery在div中选择图像

Wordpress使用.wp-caption类在div中包含带字幕的图像.我正在寻找一种方法来选择没有这个div的图像,所以我可以将它们包装在不同的div中.(在所有图像周围保持一致的边框)

<div class="blog-post-content"> 
 <div id="attachment_220" class="wp-caption alignleft" style="width: 310px">
  <a href="/somewhere/"><img class="size-medium wp-image-220" src="/path/to/image" alt="" width="300" height="280" /></a>
  <p class="wp-caption-text">Caption Text</p>
 </div>
 <p>This is the body of the post</p>
</div>
Run Code Online (Sandbox Code Playgroud)

要测试我的选择器,我只是想添加一个绿色边框.一旦选择器工作,我可以处理.wrap().

我最有希望的尝试是:

$('.blog-post-content img').parent('div:not(".wp-caption")').css('border', '2px solid green');
Run Code Online (Sandbox Code Playgroud)

......但没有运气.

jquery-selectors

2
推荐指数
1
解决办法
9243
查看次数

标签 统计

jquery-selectors ×1