2011-09-22 36 views
1

元素我有這樣的結構切換父與母

<p>Integer ac porta felis. <a href="#" class="despLeerMas">...read more</a></p> 
<div class="none masInfodespLeerMas"> onsectetur adipiscing elit. Sed condimentum dictum vestibulum. Praesent odio dolor, dapibus et consectetur quis, pulvinar eu orci. Integer ac porta felis.<a href="#" class="ocultarLeerMas"> ...read less</a></div> 

<p>Integer ac porta felis. <a href="#" class="despLeerMas">...leer más</a></p> 
<div class="none masInfodespLeerMas"> onsectetur adipiscing elit. Sed condimentum dictum vestibulum. Praesent odio dolor, dapibus et consectetur quis, pulvinar eu orci. Integer ac porta felis.<a href="#" class="ocultarLeerMas">..read less</a></div> 

,我這個

$('.despLeerMas').click(function() 
    { 
     $(this).parent().next('.masInfodespLeerMas').toggle(); 
     $(this).parent().next('.ocultarLeerMas').toggle(); 
     $(this).toggle(); 
     return false; 
    }); 
    $('.ocultarLeerMas').click(function() 
    { 
     $(this).parent().toggle(); 
     $(this).parent().parents('p').find('.despLeerMas').toggle(); ///cant' get it working 
     $(this).toggle(); 
     return false; 
    }); 

這裏特林在線:點擊.despLeerMas時http://jsfiddle.net/xwQGN/1/

隱藏顯示(並且.despLeerMas被隱藏) 當點擊.ocultarLeerMas時,div再次被隱藏 問題在於.despLeerMas未顯示出反抗N:S(我不能選擇代碼得到的,我猜)

回答

1

嘗試:

$(this).parent().prev().find('.despLeerMas').toggle(); 

Your updated fiddle.

+0

固定在同一時間哈哈哈,我用$做到了(這個).parent ().prev( 'p')找到(」 despLeerMas。)切換(); –