Nizam Ali
Nizam Ali

Reputation: 241

Display only few div and hide all other div using jquery

I have a main div <div id="divMain">, under which I've multiple divisions. But, I'm trying to display only few div's say <div id="div3"> & <div id="div4"> and hide other inside divMain. I'm not getting it. Any ideas would be greatly appreciated.

Upvotes: 1

Views: 272

Answers (3)

Milind Anantwar
Milind Anantwar

Reputation: 82231

You can use :not selector to filter out hiding few elements using their selector:

$('#divMain div:not(#div3,#div4)').hide();

In case you have inner divs in div3 and div4, you can use:

$('#divMain div:not("#div3,#div4,#div3 *,#div4 *")').hide();

Demo

Upvotes: 3

Rahul
Rahul

Reputation: 5774

$( "#div1, #div2" ).hide();

It supports multiple DOM elements.

Upvotes: 0

Adil
Adil

Reputation: 148110

First hide all div in divMain and then show the few you want using the Multiple Selector (“selector1, selector2, selectorN”).

$('#divMain div').hide();
$('#div3, #div4').show();

Upvotes: 2

Related Questions