Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

358
Views
How can I hide divs if they are empty?

I have some divs that maybe be empty (depending on server-side logic).

<div id="bar">

<div class="section" style="display:block;"></div>
<div class="section" style="display:block;"></div>
<div class="section" style="display:block;"></div>

</div>

If they don't have any html inside the div's (with class section), I just want to hide them.

How can I do this?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

jQuery has a :empty selector. So, you can simply do:

$('div.section:empty').hide();
over 4 years ago · Santiago Trujillo Report

0

Here is a CSS3 solution for anyone who is interested

div:empty {
  display:none;
}
over 4 years ago · Santiago Trujillo Report

0

Why does nobody use .filter ?

$("div.section").filter(function() {
    return this.childNodes.length === 0;
}).hide();

This is a more elegant solution compared to using .each.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!