Jquery:隐藏所有子项,然后显示特定元素 [英] Jquery: Hide all children, then show a specific element

查看:426
本文介绍了Jquery:隐藏所有子项,然后显示特定元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想隐藏div中的所有子元素。
然后显示传递给函数的特定值。

I want to hide all child elements in a div. And then show a specific one passed on to the function.

function subDisplay(name) {
   $("#navSub").each(function() {
      $(this).hide();
   });
   $(name).show();
}

然后我从onmouse事件调用该函数,如: subDisplay(#DivIwantToShow);
但是没有显示......

then i call the function from an onmouse event like: subDisplay(#DivIwantToShow); But nothing displays...

我做错了什么?

推荐答案

您需要隐藏子项而不是包含div。

You need to hide the children and not the containing div.

$(#navSub)。children()。hide();

所以现在如果你想要显示的div是父div中的一个元素,它仍然会显示,而其他div保持隐藏状态。

So now if the div you are trying to show is an element in the parent div it will still show while the others stay hidden.

这篇关于Jquery:隐藏所有子项,然后显示特定元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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