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.
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).
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".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With