2011-08-11 3 views
1

는이 같은 6 TDS 있습니다jQuery의 링크 호버에서 다음 td에 클래스를 추가하는 방법은 무엇입니까?

<td><a href="#">link</a></td> 
<td>Some text here</td> 

<td><a href="#">link</a></td> 
<td>Some other text here</td> 

<td><a href="#">link</a></td> 
<td>Some other other text here</td> 

을 그리고 난 다음 TD로 연결되는 링크 위로 마우스를 이동 한 후 addClass 싶습니다. 예 : 내가 두 번째 TD에서 링크 위에 마우스를 올려 경우 다음 TD는 예를 들어 클래스를 것 같은 활성

<td><a href="#">link</a></td> 
<td>Some text here</td> 

<td><a href="#">link</a></td> <!-- hoovering over this link --> 
<td class="active">Some other text here</td> <!-- and this td will have class active--> 

<td><a href="#">link</a></td> 
<td>Some other other text here</td> 

이 어떻게 할까? 여기

답변

2
$('a').hover(function(){ 
    $(this).parent().next().addClass('someclass'); 
}, function(){ 
    $(this).parent().next().removeClass('someclass'); 
}); 
1
jQuery(function($){ 
    $("a").hover(function(){ 
     $(this).parent().next("td").addClass("active"); 
    }); 
}); 

이것은 호버에 클래스를 추가하지만 링크에서 마우스를 가져 가면도 제거 할뿐만 아니라 fiddle

1

입니다. 또한 페이지에 다른 태그가있을 때도 작동합니다. 뿐만 아니라 td 안에.

$(document).ready(function() { 
    $("td > a").hover(function() { 
     $(this).parent().next("td").toggleClass("active"); 
    }); 
}); 
관련 문제