I am writing a custom control that includes inputting a text box and an unordered list of items below it. As the user enters a text box, I would like the matched text in the list to be bold (wrapped in tags <strong>).
$('#filterList').keyup(function() {
var $this = $(this);
clearTimeout($this.data('timer'));
$this.data('timer', setTimeout(function() {
var searchString = $this.val();
$('li').each(function() {
$(this).find('strong').replaceWith(function() {
return $(this).html();
});
$(this).html($(this).html().replace(new RegExp(searchString, "ig"), '<strong>'+searchString+'</strong>'));
});
}, 400));
});
The problem I am facing is that I want the search to be case insensitive . I was able to match the text accordingly, but replaced it, and saving the original shell becomes a problem. Also, I don't know how I feel about creating a regular expression from user input.
Suggestions please! Thank you in advance!