gpt4 book ai didi

Jquery 显示和隐藏子 div 的问题

转载 作者:太空宇宙 更新时间:2023-11-03 23:09:18 25 4
gpt4 key购买 nike

我下面的代码打开并单独显示内容。当显示内容时,我想隐藏包含类“item-show”的 href 我遇到的问题是在内容时隐藏“.item-show”显示。单击关闭按钮时应隐藏内容并再次显示 href,但目前它没有关闭。

下面是我的代码和fiddle demo here :

$(document).ready(function() {
$(".item-content").hide();
$(".item-show").on("click hover", function() {
$(this).parent('p').next(".item-content").slideDown( "slow" );
$(this).parent('p').next('.item-show').hide();
});
$("span.close-icon").on("click hover", function() {
$(this).parent('p').next(".item-content").slideUp( "slow" );
$(this).parent('p').next('.item-show').show();

});
});

最佳答案

演示:http://jsfiddle.net/n7305445/29/

使用 .slideToggle() 切换 .item-content

使用 .closest().find() 在 DOM 树中导航

$(document).ready(function() {
//PREVIEW CARD
$(".item-content").hide();
$(".item-show").on("click", function() {
$(this).closest('.item-b').find(".item-content").slideToggle( "slow" );
});
$("span.close-icon").on("click", function() {
$(this).closest('.item-content').slideUp( "slow" );
});
});

关于Jquery 显示和隐藏子 div 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33378403/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com