Skip to content

Instantly share code, notes, and snippets.

@yeco
Created December 12, 2012 07:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yeco/4265815 to your computer and use it in GitHub Desktop.
Save yeco/4265815 to your computer and use it in GitHub Desktop.
Simple jQuery pseudo-selector that matches only if the element has text in it.
jQuery.expr[':'].hasText = function(el, i) {
if(el.childNodes.length === 1 && el.firstChild.nodeType === 3) {
return jQuery.trim(el.innerHTML).length > 0;
}
return false;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment