var availableTags = [
"win the day",
"win the heart of wi",
"win the heart of someone win"
];
var autoCompNodeId = 'tags';
$("#" + autoCompNodeId).autocomplete({
source : function(requestObj, responseFunc) {
var matchArry = availableTags.slice(); //-- Copy the array
var srchTerms = $.trim(requestObj.term).split(/\s+/);
// For each search term, remove non-matches.
$.each(srchTerms, function(J, term) {
var regX = new RegExp(term, "i");
matchArry = $.map(matchArry, function(item) {
return regX.test(item) ? item : null;
});
});
// Return the match results.
responseFunc(matchArry);
},
open : function(event, ui) {
/* This function provides no hooks to the results list;
so, we have to trust the selector, for now. */
var resultsList = $("ul.ui-autocomplete > li.ui-menu-item > a");
var srchTerm = $.trim(
$("#" + autoCompNodeId).val()).split(/\s+/).join('|');
// Loop through the results list and highlight the terms.
resultsList.each(function() {
var jThis = $(this);
var regX = new RegExp('\\b' + srchTerm + '\\b', "ig");
var oldTxt = jThis.text();
jThis.html(
oldTxt.replace(regX, '<span class="srchHilite">$1</span>'));
});
}
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.