2010-06-27 53 views
0

我有一个像不能访问子元素 - jQuery的

<div class="a"> 
    <div class="b"> 
     something 
    </div> 

    <div class="c"> 
     <div class="subC"> 
      i want to access 
     </div> 
    </div> 
</div> 

和jQuery一个HTML像

$('.a').hover(function(){ 
    $(this).children('.subC').fadeOut(); 
}) 

我要访问的类 “subC的”,但上面不工作。

我也尝试

$('.a').hover(function(){ 
    $(this).children('.c .subC').fadeOut(); 
}) 

,但是这也不能正常工作!

这是什么问题的解决方案!我做错了什么?请帮助

回答

0

使用.find('selector')找到深的孩子

0

正如罗布说,使用.find找到深元素。

$('.a').hover(function() 
    { 
     $(this).find('.c .subC').fadeOut(); 
    }); 

,如果你想使用.children,写

$('.a').hover(function(){ 
    $(this).children('.c').children('.subC').fadeOut(); 
}) 
1

当一个jQuery瓶盖内,this是指由先前的jQuery操作返回的jQuery对象:

$('.a').hover(function() { 
    // 'this' is a jQuery object containing the result of $('.a') 
}) 

使用this在闭包内设置查询当前jQuery对象的范围:

$('.a').hover(function() { 
    $('.subC', this).fadeOut(); 
})