Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to hide all divs in jquery

I have several divs:

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

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

like image 918
Mythriel Avatar asked Feb 27 '12 17:02

Mythriel


2 Answers

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

$('div').hide();

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();

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

like image 130
MMM Avatar answered Sep 26 '22 11:09

MMM


for more detail you can read this : Element Selector (“element”)

this will do : $('div').hide();

there is no need of # sign which is for the id selector for jquery , if you want to hide element just write the name of element will do your task thats called as "element selector".

like image 23
Pranay Rana Avatar answered Sep 22 '22 11:09

Pranay Rana