bunjomin
10/4/2018 - 5:57 PM

Remove Empty Headings & Headers

Remove all empty headings, then remove all empty headers (in case the heading was the only item inside a header)

const RemoveEmptyHeadings = () => {
  [...document.querySelectorAll('h1, h2, h3, h4, h5, h6')].map((heading) => {
    if (heading.innerText.length < 1) {heading.remove()}
  });
}

const RemoveEmptyHeaders = () => {
  [...document.querySelectorAll('header')].map((header) => {
    if (header.innerHTML.trim().length < 1) {header.remove()}
  });
}