Search code examples
jqueryjquery-selectorsparentchildren

toggle parent's element with parent


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)


Solution

  • Try:

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

    Your updated fiddle.