I am trying to implement jQuery autocomplete box and successfully integrated into my project. Here I am giving the source for the jquery Autocomplete box as list elements.
var _array = ['<li height="45px" class="ui-menu-item ui_dropdown_item" role="presentation"><a id="ui-id-302" class="ui-corner-all ui_dropdown_focus" tabindex="-1"><img class="apps-share-chips-profile-icon" src="build/assets/apple.png" onerror="helper.onImageError(this);"><span search="text">01arun23@gmail.com</span></a></li>',
'<li height="45px" class="ui-menu-item ui_dropdown_item" role="presentation"><a id="ui-id-302" class="ui-corner-all ui_dropdown_focus" tabindex="-1"><img class="apps-share-chips-profile-icon" src="build/assets/ms.png" onerror="helper.onImageError(this);"><span search="text">aaron.lee@rescue.org</span></a></li>'];
As you see, I am giving li elements as source and binding it in jQuery as below.
$(this).data('ui-autocomplete')._renderItem = function(ul, item) {
return $(item.label).appendTo(ul);
};
So I get the functionality completed. Now what am trying to achieve is highlighting the query that the user enter, like given in this SO link.
My try as of is given below, I am trying to replace the span tag text with the query that user enters. How could I achieve this in my scenario.
$(this).data('ui-autocomplete')._renderItem = function(ul, item) {
$(item.label).find('span').replace(new RegExp('(?![^&;]+;)(?!<[^<>]*)(' + $.ui.autocomplete.escapeRegex(this.term) + ')(?![^<>]*>)(?![^&;]+;)', 'gi'), '<span style="font-weight:bold;color:Blue;">$1</span>');
return $(item.label).appendTo(ul);
};
But I couldn't able to achieve and I dont know what's going wrong in my solution. Answers are highly appreciated.
EDIT: I have added the jsfiddle link. Just want to add the highlight query functionality in that.