I am trying to get highlighting on keyword searching working right. A couple issues I am having.
- Case insensitive is working for the first word, but would like it to replace with original case word, not the lowercase searched word.
i.e. search trend, it replaces Trend with trend, I know why, but would like to figure out how to replace back the found word, not the searched word
- The second word is not matching case insensitive.
i.e. search trend micro is not matching trend Micro.
Here is jsFiddle: http://jsfiddle.net/hh2zvjft/1/
if ($(".ProjectSearch").val().length > 0) {
var searchedText = $(".ProjectSearch").val();
var wordList = searchedText.split(" ");
$.each(wordList, function (i, word) {
$(".ProjectTaskGrid:contains('" + word + "')").each(function (i, element) {
var rgxp = new RegExp(word, "gi");
var repl = '<span class="search-found">' + word + '</span>';
element.innerHTML = element.innerHTML.replace(rgxp, repl);
});
});
}
Can you please help identify the issues, and offer improvements? Thanks!
Some refererences used to arrive at code: