0

I have parent element whose id is course.

course are multiple div inside it. Inside div are having classes like mba,engineering,information technology etc.

Now i want to hide div's having management,mba,finance class.

I have tried following code:

elem = $("#course");
if (elem.hasClass("management mba finance")) {
   elem.hide();
}

But it is hiding parent $("#course") div.

How i can hide or process div's having management,mba and finance classes.

Hitesh Modha
  • 2,740
  • 5
  • 28
  • 47

4 Answers4

7

try this:

$("#course").find(".management,.mba,.finance").hide();

to hide element having all three classes:

$("#course").find(".management.mba.finance").hide();
Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
  • Thanks Milind, but finding elements using , is or condition. it will hide all div having class management.Select all elements with class "management", "mba" or "finance": – Hitesh Modha Mar 31 '14 at 13:53
  • so You want hide element that have all three classes in it?? If that is the case then check the other solution i have edited above. – Milind Anantwar Mar 31 '14 at 14:11
1

You can directly use class selector with Jquery .Hide().

$(".YourClassName").hide(); // Please replace "YourClassName" with original class 

As you described in question description -

You want to hide element which have classes like management, mba, finance.

then you can -

$("#course .management, #course .mba, #course .finance").hide();

OR

$("#course > .management,.mba,.finance").hide();

Try in Fiddle

Ishan Jain
  • 8,063
  • 9
  • 48
  • 75
  • First add the class YourClassName to the management,mba and finance class divs. – QuentinUK Mar 31 '14 at 13:51
  • Correct , but it's not the best way – Sudharsan S Mar 31 '14 at 13:55
  • @sudhar: Yes, But "Milind Anantwar" already put an answer for this. So i tried to make my answer differ from other persons. – Ishan Jain Mar 31 '14 at 14:02
  • @IshanJain, yes, there's more than one way to do it. The best answer depends what else the OP wants to do. If he only want this group of classes for this it would be better not to make another class. If he wants to do lots of things with this group of classes it would then be worth making the extra class to group them. – QuentinUK Mar 31 '14 at 14:05
  • @QuentinUK: Yes, I you are right. I agree with you. :) – Ishan Jain Mar 31 '14 at 14:12
1

It is working...

If you want to hide a div that contains all 3 classes then

$(".management.mba.finance").hide();

will work.

http://jsfiddle.net/3M5LU/

Hitesh Modha
  • 2,740
  • 5
  • 28
  • 47
0

You can use the following to hide the elements within ID and Classes

$('.className').hide();
$('#ElementID').hide();

$("#course .management, #course .mba, #course .finance").hide();

For more information you can visit the link .hide() and .show() follow the right way according to your requirements.

Try In Fiddle

nrsharma
  • 2,532
  • 3
  • 20
  • 36
TheDean
  • 275
  • 1
  • 5
  • 16