2012-03-06 81 views
1

我有一個內部div你好隱藏的div。當我將鼠標懸停在外部區域時,我希望展示內部。我很難做到這一點。我嘗試了一些變化,但仍不能得到它。jQuery顯示懸停的內部div

我將在頁面上有多個外部div。

<div class='outdiv'> 
    <h1>Content</> 
    <div class='innerdiv'></div> 
</div> 
<div class='outdiv'> 
    <h1>Content</> 
    <div class='innerdiv'></div> 
</div> 
<div class='outdiv'> 
    <h1>Content</> 
    <div class='innerdiv'></div> 
</div> 

腳本:

 $("div.listingContainer").mouseover(function() { 
      $(this).parent().siblings(".saveCompare").show(); 
     }).mouseout(function(){ 

     }); 

感謝您的幫助。

+2

Uhmmm ...你過於簡化你的HTML的例子嗎?你的jQ選擇器根本不匹配你的標記。 – vzwick 2012-03-06 10:31:26

+0

哪裏的saveCompare div? – sandeep 2012-03-06 10:32:58

+0

此外,您的問題只有一個CSS解決方案:'.outdiv:hover .innerdiv {display:block}' - 爲什麼要使用JS? – vzwick 2012-03-06 10:33:06

回答

5

你爲什麼使用jQuery? 我會用CSS懸停去這一個

.outdiv:hover .innerdiv { 
    display: block; // adjust for your method of hiding the div 
} 
0

試試這個:

$("div.outdiv").hover(function() 
{ 
    $(this).find(".innerdiv").show(); 
}, 
function() 
{ 
    $(this).find(".innerdiv").hide(); 
}); 
0

您可以指定第二個參數$()指定選擇的情況下 - jQuery API

$('.outdiv').hover(function() 
{ 
    $('.innerdiv', this).show(); 
}, function() 
{ 
    $('.innerdiv', this).hide(); 
}); 

http://jsfiddle.net/pGF3x/

0

試試這個

$(".outdiv").hover(function() 
{ 
     $(this).find(".innerdiv").show(); 
}, 
function() 
{ 
     $(this).find(".innerdiv").hide(); 
}); 
1

你應該這樣做

$("div.outerDiv").mouseover(function() { 
     $('div.innerDiv', this).show(); 
    }); 

或顯示/隱藏

$("div.outerDiv").hover(function() { 
     $('div.innerDiv', this).show(); 
    }, 
    function() { 
     $('div.innerDiv', this).hide(); 
    }); 
0
<script> 
     $(document).ready(function() { 
      $('.outdiv',this).hover(function() { 
       $('.innerdiv',this).css('opacity', '0'); 
      }, function() { 
       $('.innerdiv').css('opacity', '1.0'); 
      }); 
     }); 
</script> 

做這樣的jQuery