leodutra
5/22/2015 - 7:33 PM

Filter elements and Highlight text ( find , search , string )

Filter elements and Highlight text ( find , search , string )

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);
	}
}
.js-filtered-highlight {
  color: yellow;
}