しかなくて、他に要素がないときだけ非表示にする const children = el.children; const onlyEmptyP = children.length === 1 && children[0].tagName === 'P' && children[0].textContent.trim() === ''; if (onlyEmptyP) { el.style.display = 'none'; } }); });