Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to hide all divs inside of a parent div/container by adding an inline style to parent?

I am trying to figure out if it is possible to hide all child divs inside of a parent container by adding an inline style to the parent div. I have tried both visibility: hidden; and display: none; Neither one seem to hide the child divs. I was thinking I could just use some jquery to loop through all child divs and add an inline style to each one, although I figure there must be a way that works.

Here is an example:

CSS

  .hero-content {
      text-align: center;
      height: 650px;
      padding: 80px 0 0 0;
    }

    .title, .description {
      position: relative;
      z-index: 2
    }

HTML

<div class="hero-content">
   <div class="title"> This is a title </div>  
   <div class="description"> This is a description</div>  
</div>
like image 438
user1632018 Avatar asked Dec 21 '13 05:12

user1632018


People also ask

How do I make DIVS always fit in my parent div?

Method 1: First method is to simply assign 100% width and 100% height to the child div so that it will take all available space of the parent div. Consider this HTML for demonstration: HTML.

How do I fit a div inside another div?

To move the inner div container to the centre of the parent div we have to use the margin property of style attribute. We can adjust the space around any HTML element by this margin property just by providing desired values to it. Now here comes the role of this property in adjusting the inner div.

How do I hide a specific DIV in HTML?

To hide an element, set the style display property to “none”. document. getElementById("element"). style.


1 Answers

You cannot hide child elements using an inline style on parent element, so use display: none; for your child elements, you don't need inline style for doing this

.hero-content > div.title,
.hero-content > div.description {
   display: none;
}

Or if you are going with jQuery solution, than add a class to the parent element and than use the below selector.

.hide_this > div.title,
.hide_this > div.description {
   display: none;
}

Now add .hide_this class on the parent element using jQuery.

$(".hero-content").addClass("hide_this");

Demo (Using .addClass())


Or if you are a fan of inline style than here you go

$(".hero-content .title, .hero-content .description").css({"display":"none"});

Demo 2

like image 57
Mr. Alien Avatar answered Nov 15 '22 13:11

Mr. Alien