Run ❯
Get your
own
website
Result Size:
625 x 565
×
Change Orientation
Save Code
Change Theme, Dark/Light
Go to Spaces
<!DOCTYPE html> <html> <body> <h3>A demonstration of how to access a DATALIST element</h3> <form> <input list="myDatalist"> <datalist id="myDatalist"> <option value="Internet Explorer"> <option value="Firefox"> <option value="Chrome"> <option value="Opera"> <option value="Safari"> </datalist> </form> <p>Click the button to get the number of option elements in the datalist.</p> <button onclick="myFunction()">Try it</button> <p><strong>Note:</strong> The input element's list attribute is used to bind it together with the datalist element.</p> <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("myDatalist").options.length; document.getElementById("demo").innerHTML = "Found " + x + " options in the list."; } </script> </body> </html>