Skip to content

Instantly share code, notes, and snippets.

@hassansw
Created June 19, 2019 11:21
Show Gist options
  • Save hassansw/693e467c4016b9d5ec46bf0e10334862 to your computer and use it in GitHub Desktop.
Save hassansw/693e467c4016b9d5ec46bf0e10334862 to your computer and use it in GitHub Desktop.
Check if an html string has text or not (for html editors)
fucntion isEmpty(htmlString) {
if (htmlString) {
const parser = new DOMParser();
const { textContent } = parser.parseFromString(htmlString, "text/html").documentElement;
return !textContent.trim();
} else {
return true;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment