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

237
Views
JQuery delete empty divs

<div class="container-mob"></div>

I have multiple divs like this, some of them are empty (have no children) and all of them have the same class name. I want to remove the empty divs. I've tried:

if ($('.container-mob').is(':empty')) { 
          $('.container-mob').remove();
        }

Is there any way to do this with jQuery or JavaScript?

Screenshot divs

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Try this one: $('.container-mob:empty').remove()

console.log('all empty container',$('.container-mob:empty').length);

$('.container-mob:empty').remove();

console.log('after remove all empty container',$('.container-mob:empty').length);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    
    <div class="container-mob"></div>
    <div class="container-mob"></div>
    <div class="container-mob"></div>
    <div class="container-mob"></div>
    <div class="container-mob">not empty</div>

about 4 years ago · Juan Pablo Isaza Report

0

You can simply get all empty div's like and call remove() function on empty div's array

HTML:

<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block">Data</div>
<div class="block"></div>
<div class="block">Data</div>

JQuery:

$(".block:empty").remove()
about 4 years ago · Juan Pablo Isaza 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!