Last active
January 14, 2024 07:57
-
-
Save barneycarroll/981147 to your computer and use it in GitHub Desktop.
`:notext` is an alternative to the `:empty` selector for jQuery. Elements consisting exclusively of an amount of whitespace or HTML comments will be returned.
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
/* | |
jQuery's ':empty' selector only returns true if the element contains no text node, or whose text node consists exclusively of zero or more spaces and tabs. This ':notext' selector will return true for elements whose text nodes can also contain line breaks (any whitespace character) and HTML comments. | |
*/ | |
$.expr[':'].notext = function detectNoText(x){ | |
return x.innerHTML && x.innerHTML.replace(/(<!--.*(?!-->))|\s+/g, '').length === 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A must-have in jQuery! Thanks for the code.