Is there a clean and robust way in which I can test (using pure javascript or also jQuery) if an HTML element can contain some text?
For instance, <br>
, <hr>
or <tr>
cannot contain text nodes, while <div>
, <td>
or <span>
can.
The simplest way to test this property is to control the tag names. But is this the best solution? I think it is one of the worst...
EDIT: In order to clarify the sense of the question, need to point out that the perfect answer should consider two problems:
- According to HTML standards, can the element contain a text node?
- If the element contains some text, will it be shown?
Obviously, there is a sub-answer for each point of the previous list.
See Question&Answers more detail:os