/ Published in: JavaScript

URL: http://pjotor.com
Quick 'n' dirty
Expand |
Embed | Plain Text
var multiWord = function(string){ return new RegExp("(" + string.split(" ").join(")|(") + ")",'gi'); } $.expr[":"].contains = $.expr.createPseudo(function(arg) { return function( elem ) { return multiWord(arg).test($(elem).text()); }; }); function highLight(string, selector) { selector = selector || ""; var re = multiWord(string); $(selector + ":contains(" + string + ")").each(function(){ $(this).html( $(this).text().replace(re, function($1){ return "<em>" + $1 + "</em>"; }) ); }); }
You need to login to post a comment.