I have a problem with my autocomplete script. It works fine everywhere except IE8. When the list is large the whole page becomes unresponsive and CPU usage goes up to almost 100% in IE8.
_renderItem = function(ul, item) {
var html = "";
if (item.NoDataFound) {
html = "No data found";
} else {
if (textField.val() != "") {
html = item.DisplayName.replace(new RegExp("(" + preg_quote(textField.val()) + ")", 'gi'), "<strong>$1</strong>"); // suggest message & Highlight matching part
} else {
html = item.DisplayName;
}
}
return $("<li><a>" + html + "</a></li>")
.data("item.autocomplete", item)
.appendTo(ul);
};
Could the problem be the appendTo(ul) line, that appends every item to the ul individually. Can I somehow append the whole list only once, when the last element is reached for example?