Attempting to filter out content on the page based on a jQuery UI autocomplete search. When the user is typing content not related to the search will switch to display: none; so only the content relevant to the search is displayed.
HTML
<div class="items" data-id="Get Milk">Get Milk on the way home</div>
<div class="items" data-id="Drop by Phil's">Drop by Phils house</div>
<div class="items" data-id="Grab a Sandwich">Grab a sandwich</div>
<input id="auto" type="text" />
Javascript
$(function () {
var source = $(".items").map(function () {
return $(this).data("id");
}).get();
$("#auto").autocomplete({
source: source
});
});
Attempting with
$(document).ready(function () {
var search = $("#auto").html();
var results = $(".items").html();
if (search == results) {
$(".items").css("display", "block");
}
else {
$(".items").css("display", "none");
}
});
Now I do understand that I need to refer to the individual "items" and this also needs to be demystified. jsfiddle: http://jsfiddle.net/J5rVP/25/ Courtesy Andrew Whitaker, from bit.ly/U1gjr2