Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6237763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:05:27+00:00 2026-05-24T11:05:27+00:00

Is it possible to hide a div with css if the div has no

  • 0

Is it possible to hide a div with css if the div has no child div’s with a specific class name?

<div class="parent">
 This div must be hidden
</div>

<div class="parent">
 This div must be visible
 <div class="child">
 child div
 </div>
</div>

If it’s not possible with CSS, maybe with javascript or jQuery?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T11:05:28+00:00Added an answer on May 24, 2026 at 11:05 am

    I don’t think this is possible with just CSS, but it is definitely possible with Javascript.

    You have to
    – find all divs with class parent
    – find all those with a child div with class child
    – if there is no such child, set style.display = none

    Now, with pure javascript this can be a bit complicated. You can use the getElementsByClassName from this question and then apply the above logic:

    //getElementsByClassName from @CMS's answer to the linked question
    var parentDivs = getElementsByClassName(document, "parent"); 
    for(var i=0; i<parentDivs.length; i++)
    {
        var children = getElementsByClassName(parentDivs[i], "child");
        if(!children || children.length == 0)
        {
            parentDivs[i].style.display = "none";
        }
    }
    

    With jQuery, this is lot more simple:

    $(".parent").each(function()
    {
        if($(this).children(".child").length == 0)
        {
            $(this).hide();
        }
    });
    

    Live Example: http://jsfiddle.net/nivas/JWa9r/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to set the CSS properties of a DIV to not initially
Possible Duplicate: Complex CSS selector for parent of active child I want to match
Possible Duplicate: Adding show/hide to my div tags the hide/show div tags is not
Is it possible to combine a slideshow and show / hide div functionality? My
Possible Duplicate: how to hide a div after some time period? i need to
I'm not sure if this is easily possible, but would be really handy if
Is it possible to detect when jQuery has fired it's .hide() method on an
Possible Duplicate: JS/jQuery (Hide div, show div on click) I'm new to web development
Is it possible to hide name of *.php file in $(document).ready(function(){ $.getJSON(getdata.php, function(returned_data) {
It is obviously possible to hide individual data points in an Excel line chart.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.