I want to make matched text in string bold in autocomplete I got great help from this link.
This doesnt it for single word or word which are in sequence I want to make words bold no matter in which order they are.
I want to make each and every word matching in the string bold
var t = "Cadbury Gems 100gm Tasty";
var wordArr = 'gems tasty'.toLowerCase().replace(/\b[a-z]/g, function (letter) {
return letter.toUpperCase();
}).split(' ');
$.each(wordArr, function (i) {
console.log(wordArr[i]);
var re = new RegExp("^" + wordArr[i], "i");
t = t.replace(re, "<span style='font-weight:bold;color:Blue;'>" + wordArr[i] + "</span>");
})
console.log(t);
var li = $("<li></li>")
//.data("item.autocomplete", item)
.append("<a style='text-align:left'>" + t + "</a>")
.appendTo($('#ul'));
MY Fiddle
I tried with $.each
But doesnt work. Any ideas.