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,
>
I believe you're looking for a list of void HTML tags:
The following is a complete list of the void elements in HTML:
area, base, br, col, command, embed, hr, img, input, keygen, link, meta, param, source, track, wbr
From there you would just test the node to see if it is in the list. For example:
var voidNodeTags = ['AREA', 'BASE', ...];
var isNodeVoid = function (node) {
return voidNodeTags.indexOf(node.nodeName) !== -1;
};
http://jsfiddle.net/3uQjH/