Reputation: 2790
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
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
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
Reputation: 2790
It is working...
If you want to hide a div that contains all 3 classes then
$(".management.mba.finance").hide();
will work.
Upvotes: 1
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();
Upvotes: 1