2011-01-06 3 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를 가질 수 없습니다, 그것은 (당신이보고있는 것처럼) 일반적으로 첫 번째 인스턴스 만에 부착 ... 일부 방법을 실패 할 수 있습니다. 응답을

+0

감사를

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

을 그리고 $(".button")$("#button")에서 선택을 변경하는 대신

는 경우이 같은 여러 요소에 대한 클래스를 사용! – curious

관련 문제