Javascript examples for DOM HTML Element:Datalist
The options collection returns a collection of all the options in a <datalist> element.
Property | Description |
---|---|
length | Returns the number of <option> elements in the collection. |
Method | Description |
---|---|
[index] | <option> with the specified index (starts at 0). |
item(index) | <option> with the specified index (starts at 0). |
namedItem(id) | <option> with the specified id. |
An HTMLCollection Object, representing all <option> elements in the <datalist> element.
The following code shows how to Find out how many options there are in a specific <datalist> element:
<!DOCTYPE html> <html> <body> <form> <input list="browsers" name="browser"> <datalist id="browsers"> <option value="A"> <option value="B"> <option value="C"> <option value="D"> <option value="E"> </datalist> </form>//from w w w . j a v a 2 s . com <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("browsers").options.length; document.getElementById("demo").innerHTML = "Found " + x + " options in the list."; } </script> </body> </html>