用父对象切换父元素

问题描述 投票:1回答: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;
    });

在线:http://jsfiddle.net/xwQGN/1/

单击.despLeerMas(和.despLeerMas隐藏)时单击.ocultarLeerMas再次隐藏div时显示隐藏。问题是.despLeerMas不再显示:S(我猜不到选择代码,我猜)

jquery jquery-selectors parent children
1个回答
1
投票

尝试:

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

Your updated fiddle.

© www.soinside.com 2019 - 2024. All rights reserved.