With bootstrap-3-typeahead, I think you cannot use the template property. In this case, it is better to use highlighter . Example:
$('#employees').typeahead({ highlighter: function (item) { var parts = item.split('#'), html = '<div class="typeahead">'; html += '<div class="pull-left margin-small">'; html += '<div class="text-left"><strong>' + parts[0] + '</strong></div>'; html += '<div class="text-left">' + parts[1] + '</div>'; html += '</div>'; html += '<div class="clearfix"></div>'; html += '</div>'; return html; }, source: function (query, process) { var employees = []; return $.post('employee/search', { query: '%' + query + '%' }, function (data) {
So you can create a displayed html template.
If you want to keep the highlight function use this regex
var name = parts[1].replace(new RegExp('(' + query + ')', 'ig'), function ($1, match) { return '<strong>' + match + '</strong>' });
and
html += '<div class="text-left">' + name + '</div>';
source share