78
rated 0 times
[
82]
[
4]
/ answers: 1 / hits: 18182
/ 12 Years ago, fri, march 23, 2012, 12:00:00
I'm using a jquery function I found to find words in a div and highlight them. I'm using this along with a search tool so the case is not always going to match the words exactly. How can I convert this to make it case insensitive?
$.fn.highlight = function(what,spanClass) {
return this.each(function(){
var container = this,
content = container.innerHTML,
pattern = new RegExp('(>[^<.]*)(' + what + ')([^<.]*)','g'),
replaceWith = '$1<span ' + ( spanClass ? 'class=' + spanClass + '' : '' ) + '>$2</span>$3',
highlighted = content.replace(pattern,replaceWith);
container.innerHTML = highlighted;
});
}
More From » jquery