How to delete all <div> which contain only whitespaces+empty nested elements?

How to delete all <div> which contain only whitespaces+empty nested elements?

How can I remove all <div> elements which contain only whitespaces and nested empty elements?

Example. The following <div> elements with class="foobar" should be found and removed:

  1. <div class="foobar">
  2. <div>
  3.   "blank"<br>"blank"<br><br>
  4. </div>
  5. &nbsp;
  6. <p>
  7. </div>

"blank" in the example above should obviously not mean the text "blank" but the correspondig char