1

我有一个具有这种结构的 div:

  <div class="post" id="post-160439">
       <a href="http://site blablabla" title="blablablabllba">
       <img width="240" height="180" src="myimage.jpg" 
            class="attachment-240x180 wp-post-    image" alt="my alt" title="my title"></a>
  </div>

而且我想在悬停时更改图像,我(我认为)完成了大部分工作,但无法仅更改此图像,而不是所有图像,就像这样;

    $('.wp-post-image').attr('src','my new image');

它会更改所有图像,我如何告诉 jquery 更改 divID.wp-post-image?

谢谢!!

4

3 回答 3

1

尝试

$('#' + varHere + ' .wp-post-image').attr('src','my new image');
于 2013-04-01T18:29:46.987 回答
0

由于您有多个带有图像的 div,您可以尝试以下操作:

  $('div .post').each(function(){
     $(this).find('img').hover(function(){
       $(this).prop('src','my new image');
     },
     function(){
       //  callback
      }
      );
  });
于 2013-04-01T18:30:26.497 回答
0

更快的选择:

$( document.getElementById( "post-160439" ) ).find( 'wp-post-image' ).attr('src','my new image');
于 2013-04-01T18:40:25.687 回答