2011-01-06 4 views
1

私はトグルビジビリティdivを持っていますが、テーブルの外では動作しますが、内部では動作しません。どんな助け?テーブルの外で作業中に切り替えないでください

<!DOCTYPE html> 
<html> 
<head> 
    <script src="http://code.jquery.com/jquery-1.4.4.js"></script> 
<style type="text/css"> 
#hidden{ 
    background-color:gray; 
    width:120px; 
    text-decoration:none; 
    font-size:x-large; 
    top:120px; 
    color:black; 
    display:none; 
    border:thin; 
    border-bottom-color:gray; 
} 

.style1 { 
    border-style: solid; 
    border-width: 1px; 
} 
.style2 { 
    border-width: 1px; 
} 

</style> 
</head> 

<body> 

    <p id="button"><a href="#">Toggle</a></p> 

<div id="hidden">woot</div> 
<script> 

$("#button").hover(function() { 
$("#hidden").toggle(); 
}); 
</script> 

<table style="width: 35%" cellspacing="1" class="style1"> 
    <tr> 
     <td class="style2" style="width: 164px"><p id="button"><a href="#">Toggle</a></p> 
</td> 
     <td class="style2"><div id="hidden">woot</div></td> 
    </tr> 
    <tr> 
     <td class="style2" style="width: 164px">&nbsp;</td> 
     <td class="style2">&nbsp;</td> 
    </tr> 
</table> 

</body> 
</html> 

答えて

1

あなたがページに二度使用したのと同じIDを持つことはできません、それは(あなたが見ているような)通常は最初のインスタンスにアタッチ... に何らかの方法を失敗します。代わりに

、このような複数の要素のための場合、クラスを使用します。応答のための

<p class="button"><a href="#">Toggle</a></p> 

そして$("#button")から$(".button")

+0

にあなたのセレクタを変更するありがとう! – curious

関連する問題