My autocomplete results for each item looks something like this:
<h3>Celebrity Sweepstakes</h3><p>0 episodes</p>
But I want only the title inside the H3 to be highlighted. See the 'highlight' function below. I'm not sure how to change that original RegExp to only replace inside the title.
$(".show_autocomplete").autocomplete("/shows.js", {
minChars: 2,
max: 100,
formatItem:function(item, index, total, query){
return "<h3>" + item.title + "</h3><p>" + item.episodes + " episodes</p>"
},
formatMatch:function(item){
return item.title;
},
formatResult:function(item){
return item.title;
},
dataType:'json',
parse:function(data) {
return $.map(data, function(item) {
return {
data: item,
value: item.title,
result: item.title
}
});
},
highlight: function(value, term) {
var title = value.split("</h3>")[0].replace("<h3>", ""); //only replace inside this?
return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<strong>$1</strong>"); //original regexp
}
});