如何在jQuery中隐藏所有div [英] how to hide all divs in jquery

查看:94
本文介绍了如何在jQuery中隐藏所有div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个div:

<div id="div-1"></div>
<div id="div-2"></div>
<div id="div-3"></div>
<div id="div-4"></div>

如何用jquery隐藏它们.我使用了$('#div').hide();,但是没有用.

How can I hide them all with jquery. I used $('#div').hide(); and did not work.

推荐答案

您正在选择器中使用ID.只需使用:

You are using an id in your selector. Simply use:

$('div').hide();

但是,这实际上将隐藏所有div.您如何只隐藏ID为div-x形式的div?

However that will hide literally all divs. How about you hide only divs that have an id in the form of div-x?

$('div[id^="div-"]').hide();

这只会隐藏您提到的div,而不会隐藏其他div(这可能是有问题的).

This will only hide the divs you mentioned without hiding other divs (which might be problematic).

这篇关于如何在jQuery中隐藏所有div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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