与父级切换父级的元素 [英] toggle parent's element with parent

查看:109
本文介绍了与父级切换父级的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个结构

<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(我想我无法获得选择代码)

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)

推荐答案

尝试:

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

您更新的小提琴.

这篇关于与父级切换父级的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆