JSFiddle - React, Tailwind, and code Playground
by davehol
HTML
<script src="https://www.tutorialrepublic.com//examples/js/typeahead/0.11.1/typeahead.bundle.js"></script>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<div class="typeahead">
<input class="typeahead" type="text">
</div>
JavaScript
$(document).ready(function(){
// Defining the local dataset
var cars = ['Audi', 'BMW', 'Bugatti', 'Ferrari', 'Ford', 'Lamborghini', 'Mercedes Benz', 'Porsche', 'Rolls-Royce', 'Volkswagen'];
// Constructing the suggestion engine
var cars = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
local: cars
});
// Initializing the typeahead
$('.typeahead').typeahead({
hint: true,
highlight: true, /* Enable substring highlighting */
minLength: 1 /* Specify minimum characters required for showing suggestions */
},
{
name: 'cars',
source: cars
});
});