<div class="box"></div>
<div class="box"></div> <!-- Hide -->
<div class="box"></div> <!-- Hide -->
<div class="box"></div> <!-- Hide -->
I need to hide all this div but not the first div.
我需要隐藏所有这个div而不是第一个div。
I could do something like this:
我可以这样做:
jQuery('.box').hide();
jQuery('.box').first().show();
Is there a way to remove the first .box
from the array before .hide()
em?
有没有办法在.hide()em之前从数组中删除第一个.box?
5 个解决方案
#1
32
jQuery('.box').slice(1).hide()
#3
6
try
jQuery('.box').not(':first').hide();
comparison:
@T.J.Crowder is right the code i have suggested does the extra parsing that can be avoided by .slice
as suggested by @zch
@ T.J.Crowder是对的,我建议的代码可以通过@zch建议的.slice来避免额外的解析
HERE is the profile of my code (0.8ms) and HERE is the profile of @zch's code (0.53ms) see the difference
这里是我的代码的配置文件(0.8毫秒),这里是@ zch的代码(0.53毫秒)的配置文件,看到差异
#4
1
jQuery('.box').not(':eq(0)').hide();
That said, I prefer Residual Envy's solution.
也就是说,我更喜欢Residual Envy的解决方案。
#5
1
try :
jQuery('.box:gt(0)').hide();
#1
32
jQuery('.box').slice(1).hide()
#2
#3
6
try
jQuery('.box').not(':first').hide();
comparison:
@T.J.Crowder is right the code i have suggested does the extra parsing that can be avoided by .slice
as suggested by @zch
@ T.J.Crowder是对的,我建议的代码可以通过@zch建议的.slice来避免额外的解析
HERE is the profile of my code (0.8ms) and HERE is the profile of @zch's code (0.53ms) see the difference
这里是我的代码的配置文件(0.8毫秒),这里是@ zch的代码(0.53毫秒)的配置文件,看到差异
#4
1
jQuery('.box').not(':eq(0)').hide();
That said, I prefer Residual Envy's solution.
也就是说,我更喜欢Residual Envy的解决方案。
#5
1
try :
jQuery('.box:gt(0)').hide();