4
4
4eloBek2015-09-01 11:35:25
JavaScript
4eloBek, 2015-09-01 11:35:25

How to consider empty element even with spaces?

For example, this is in HTML :

<div id="content">
<b><i></i>g</b>
</div>

And this in JS :
$('#content *:empty').each(function() {
      $(this).remove();
});

Removes empty tags . Good. But if you put at least 1 space, the tag will remain . (
How can I make sure that tags with spaces ( regardless of their number ) are also deleted?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Kovalsky, 2015-09-01
@4eloBek

If a crutch - You can parse the contents
You can remove spaces and check the length of the string. Well, delete if empty

A
Andrew, 2016-07-22
@iCoderXXI

I abandoned direct dynamic manipulations in the DOM with either jQuery or Vanilla JS. In my opinion, this is evil, which leads to complete and total unpredictability of the application's behavior and the formation of an extensive field for unmanaged bugs.
Our path is React.JS, when interfaces are generated from data, and you only change the data.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question