Open mindplay-dk opened 8 years ago
We probably ought to have an extra function to check if a given node is an HTMLElement
, and then use that to make an extra assertion before relying on children
- something like:
function isHTMLElement(node) {
return node instanceof HTMLElement;
}
function isEmptyInlineElement(node) {
if (isHTMLElement(node)) {
if (node.children.length > 1) {
return false;
}
if (node.children.length === 1 && node.textContent.trim() !== '') {
return false;
}
if (node.children.length === 0) {
return node.textContent.trim() === '';
}
return isEmptyInlineElement(node.children[0]);
}
return false;
}
I agree with trying to implement the right check
@rrees adding labels appears to have unassigned you 😢 (that was not intentional)
In this function, did you really mean
node
orelement
?Because
Node
objects do not have thechildren
property - onlyElement
objects have that.