jQuery AutoComplete Replace Text with Html
$("textbox").autocomplete({
minLength: 3,
delay: 1000,
source: function (request, response) {
$.ajax({
type: "GET",
url: "use your url here",
dataType: "json",
data: { Id: DataId },
async: false,
success: function (data) {
response($.map(data, function (item) {
return {
id: item.Id,
value: item.TagValue,
label: item.Term.replace("Use", "<span style='color:red;font-weight:bold;'>" + "USE" + "</span>")
}
}));
}
});
},
select: function (event, ui) {
var a = ui.item;
a = a.value;
$(this).val(a);
event.preventDefault();
// Do something with "ui.item.Id" or "ui.item.Name" or any of the other properties you selected to return from the action
}
}).data("ui-autocomplete")._renderItem = function (ul, item) {
// only change here was to replace .text() with .html()
return $("<li></li>")
.data("item.autocomplete", item)
.append($("<a></a>").html(item.label))
.appendTo(ul);
};
minLength: 3,
delay: 1000,
source: function (request, response) {
$.ajax({
type: "GET",
url: "use your url here",
dataType: "json",
data: { Id: DataId },
async: false,
success: function (data) {
response($.map(data, function (item) {
return {
id: item.Id,
value: item.TagValue,
label: item.Term.replace("Use", "<span style='color:red;font-weight:bold;'>" + "USE" + "</span>")
}
}));
}
});
},
select: function (event, ui) {
var a = ui.item;
a = a.value;
$(this).val(a);
event.preventDefault();
// Do something with "ui.item.Id" or "ui.item.Name" or any of the other properties you selected to return from the action
}
}).data("ui-autocomplete")._renderItem = function (ul, item) {
// only change here was to replace .text() with .html()
return $("<li></li>")
.data("item.autocomplete", item)
.append($("<a></a>").html(item.label))
.appendTo(ul);
};
Comments
Post a Comment