Created
June 19, 2019 11:21
-
-
Save hassansw/693e467c4016b9d5ec46bf0e10334862 to your computer and use it in GitHub Desktop.
Check if an html string has text or not (for html editors)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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