Skip to content

Instantly share code, notes, and snippets.

@leodutra
Last active April 26, 2016 03:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leodutra/dcf6a2d5ba5c48e9b781 to your computer and use it in GitHub Desktop.
Save leodutra/dcf6a2d5ba5c48e9b781 to your computer and use it in GitHub Desktop.
Filter elements and Highlight text ( find , search , string )
.js-filtered-highlight {
color: yellow;
}
function highlightAndfilter($root, $elem, text) {
//text = String(text).replace(/(['"])/gim, '\\$1'); // escape quotes and double quotes
var cssClass = 'js-filtered-out';
$root = $($root);
$elem = $elem ? $root.find($elem) : $root.children();
$elem.filter('.' + cssClass).removeClass('.' + cssClass).show();
if (text) {
$elem.not(':contains("'+text+'")').hide().addClass(cssClass);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment