Hitesh Modha
Hitesh Modha

Reputation: 2790

Hide Element by jquery classes

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.

Upvotes: 0

Views: 113

Answers (4)

TheDean
TheDean

Reputation: 285

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

Upvotes: 0

Milind Anantwar
Milind Anantwar

Reputation: 82241

try this:

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

to hide element having all three classes:

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

Upvotes: 7

Hitesh Modha
Hitesh Modha

Reputation: 2790

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/

Upvotes: 1

Ishan Jain
Ishan Jain

Reputation: 8171

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

Upvotes: 1

Related Questions