toggle parent's element with parent

拜拜、爱过 提交于 2019-12-11 13:56:17

问题


I have this structure

<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>

and i'm tring with this

$('.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;
    });

online here: http://jsfiddle.net/xwQGN/1/

The hidden is shown when clicking .despLeerMas (and .despLeerMas is hidden) when clicking .ocultarLeerMas the div is hidden again the problem is that .despLeerMas is not shown again :S (I can't get with the selection code, i guess)


回答1:


Try:

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

Your updated fiddle.



来源:https://stackoverflow.com/questions/7513062/toggle-parents-element-with-parent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!