2011-07-02 38 views
0

我解決以下問題 - 我已經從數據庫表和每一個這個項目的項目我的網頁語句打印到DIV。如果鼠標在這個div用戶移動光標,這樣的話就會顯示分度等信息。jQuery的 - 「這個」元素和「父(S)」

  <div class="dost"> 
       3 days | 
       <span>deliv</span> 
       <div class="deliv_bubble"> 
        <div><strong>aaa</strong></div> 
             <div><strong>bbb</strong></div> 
             <div><strong>ccc</strong></div> 
       </div> 
      </div> 

$('div.dost span').mouseover(function() { 
    $('div.dost div.deliv_bubble').show(); 
}); 

在頁面上有例如100次打印這個html結構。我的問題是,當我移動鼠標光標放在文本deliv,所以DIV deliv_bubble將被顯示,但不幸的是100倍......我想顯示這只是一個時間......

誰能幫助我,請我在做什麼錯? 謝謝

回答

1

這樣做:

$('div.dost span').mouseover(function() { 
    $(this).parent().find('div.deliv_bubble').show(); 
}); 

$(this).parent()將返回相應的父div.dost

希望這有助於。乾杯

+0

謝謝'Edgar'這麼快和偉大的答案! – user1946705

+0

不客氣:) –

1

試試這個:

$('div.dost span').mouseover(function() { 
    $(this).siblings('div.deliv_bubble').show(); 
}); 
1
$('div.dost span').mouseover(function() { 
    $(this).siblings('.deliv_bubble').show(); 
}); 

應該這樣做。