Last active
April 26, 2016 03:27
-
-
Save leodutra/dcf6a2d5ba5c48e9b781 to your computer and use it in GitHub Desktop.
Filter elements and Highlight text ( find , search , string )
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
.js-filtered-highlight { | |
color: yellow; | |
} |
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
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