jQuery select image in div if image parent does't have a certain class.

Posted by Alex on Stack Overflow See other posts from Stack Overflow or by Alex
Published on 2010-03-31T20:22:07Z Indexed on 2010/03/31 20:33 UTC
Read the original article Hit count: 205

Filed under:

Wordpress wraps images with captions in a div with a class of .wp-caption. I'm looking for a way to select images that don't have this div so I can wrap them in different div. (to keep a consistent border around all the images)

<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>

To test my selector, I'm just trying to add a green border. I can handle the .wrap() once the selector is working.

The most promising of my attempts is:

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

... but no luck.

© Stack Overflow or respective owner

Related posts about jquery-selectors