2012-10-29 177 views
0

我已經得到了下面的標籤結構。這在頁面上重複了9次。我希望當我懸停在9個'itemInfo'div中的一個上時,它將把所有的文本顏色改變爲白色(包括鏈接)。我如何使用jQuery選擇所有這些?看看我下面的嘗試。選擇div內的所有標籤

<div class="row itemInfo"> 
    <div class="row"> 
     <div class="twelve columns itemImage"> 
      <img src="http://lorempixel.com/250/185/abstract/"> 
      </div> 
     </div> 
    </div> 

    <div class="row"> 
     <div class="twelve columns itemDetails"> 
      <h3><a href="#">title</a></h3> 
      <p class="quiet">submitted by <a href="#">designer</a></p>     
     </div> 
    </div> 
</div> 

我嘗試:

$(".itemInfo").hover(function() { 
    $(this).find('h3 a').addClass('itemInfoActive'); 
    $(this).find('p').addClass('itemInfoActive'); 
    $(this).find('p a').addClass('itemInfoActive'); 
    return false; 
+1

爲什麼你沒有爲你工作? –

+0

你有一個缺少'});''在你的'懸停'功能結束... – udidu

回答

0
$(".itemInfo").mouseenter(function() { 
    $('a,p,h3',this).addClass('itemInfoActive'); 
}); 
0

您可以使用此通用選擇:

$(".itemInfo").hover(function() {  
    $(this).find('*').addClass('itemInfoActive'); 
}); 
+0

喲布魯夫,你錯過了'.parent'':'' –

0

檢查了這一點工作演示http://jsfiddle.net/E8uws/使用mouseoutmouseover =>http://jsfiddle.net/yUf4Q/

如果你熱衷於閱讀更多:http://api.jquery.com/category/selectors/

休息應該幫助您的需要:) 代碼

$(function() { 
    $(".itemInfo").hover(function() { 
      $(this).parent().find('*').css('color', 'red'); 
    }); 
});​ 

額外的代碼

$(function() { 
    $(".itemInfo").mouseover(function() { 
     $(this).parent().find('*').css('color', 'red'); 
    }).mouseout(function() { 
     $(this).parent().find('*').css('color', 'black'); 

    }); 
});​