Basic Usage of Awesomplete
gh-pagesTo use Awesomplete, first include the CSS and JS files in your HTML. You can then enable autocomplete by adding the awesomplete class to an <input> element.
There are three primary ways to provide suggestions:
- Comma-separated string: Use the
data-listattribute with a string of items. - HTML
<datalist>: Use thelistattribute pointing to the ID of a<datalist>for native fallback. - CSS Selector: Use the
data-listattribute with a CSS selector (e.g.,#idor.class) pointing to a<ul>or similar element.
<!-- 1. Include assets -->
<link rel="stylesheet" href="awesomplete.css" />
<script src="awesomplete.js" async></script>
<!-- 2. Option A: Comma-separated string -->
<input class="awesomplete" data-list="Ada, Java, JavaScript" />
<!-- 2. Option B: Using <datalist> for native fallback -->
<input class="awesomplete" list="mylist" />
<datalist id="mylist">
<option>Ada</option>
<option>Java</option>
</datalist>
<!-- 2. Option C: Using a CSS selector for a list element -->
<input class="awesomplete" data-list="#mylist" />
<ul id="mylist">
<li>Ada</li>
<li>Java</li>
</ul>