jqueryHow do I use jQuery autocomplete to create a search box?
Using jQuery autocomplete to create a search box is simple. First, you need to include the jQuery library and jQuery UI library in the HTML document. Then, you need to create an input element with an ID and set the data source for the autocomplete widget. Here is an example code block:
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<input type="text" id="searchBox">
<script>
$( "#searchBox" ).autocomplete({
source: [ "apple", "banana", "orange" ]
});
</script>
This code will create an input element and enable autocomplete on it with the given data source.
The parts of this code are:
- Include jQuery library:
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
- Include jQuery UI library:
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
- Create an input element with an ID:
<input type="text" id="searchBox">
- Set the data source for the autocomplete widget:
source: [ "apple", "banana", "orange" ]
- Initialize the autocomplete widget on the input element:
$( "#searchBox" ).autocomplete({
For more information on jQuery autocomplete, see the jQuery UI Autocomplete documentation.
More of Jquery
- How do I use jQuery ZTree to create a hierarchical tree structure?
- How do I use jQuery to zip files?
- How do I use jQuery to detect window resize events?
- How do I download a zip file using jQuery?
- How can I get the y position of an element using jQuery?
- How do I use a jQuery x-csrf-token?
- How do I add a zoom feature to my website using jQuery?
- How can I prevent jQuery XSS vulnerabilities?
- How can I use jQuery to yield a result?
- Include latest jQuery library version into HTML
See more codes...