[英]not able to show and hide div
<ol class="novice">
<li>
<p class="glava">HTML</p>
<div class="vsebina">
<p>Hyper Text Markup Language (slovensko jezik za označevanje nadbesedila...</p>
</div>
</li>
<li>
<p class="glava">CSS</p>
<div class="vsebina">
<p>Cascading Style Sheets (kratica CSS) so predloge, ki določajo izgled ...</p>
</div>
</li>
When I click on the p class="glava"
I want that the specific div
that is located in this li
is shown( .show()
) and all the others( div
s) are hidden. 当我单击
p class="glava"
我希望显示位于此li
中的特定div
( .show()
),并隐藏所有其他div
( div
)。 I have around ten li
. 我十点左右
li
。
$("p.glava").click(function () {
$(something).show();
//$(everything else ).hide();
With Slide Toggle animation 带有幻灯片切换动画
$(".glava").click(function () {
$(this).closest('li').find('.vsebina').slideToggle('slow');
});
With Fade Toggle animation 带有淡入淡出切换动画
$(".glava").click(function () {
$(this).closest('li').find('.vsebina').fadeToggle('slow');
});
And just to hide 只是躲起来
$(".glava").click(function () {
$(this).closest('li').find('.vsebina').hide();
});
Numerous ways to traverse to isolate specific instance. 遍历以隔离特定实例的多种方法。 All start with
this
being the element instance of that class that was clicked 开始时都
this
是被点击的那个类的元素实例
$("p.glava").click(function () {
$('.vsebina').hide();
$(this).parent().find('.vsebina').show()
// or
$(this).next('.vsebina').show()
// or
$(this).siblings('.vsebina').show()
}) ;
References 参考文献
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.