Get Datalist Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Datalist


The Datalist object represents an HTML <datalist> element.

You can access a <datalist> element by using getElementById():

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

  <input list="myDatalist"> 
  <datalist id="myDatalist"> 
    <option value="Internet Explorer">
    <option value="Firefox">
    <option value="Chrome">
    <option value="Opera">
    <option value="Safari">
</form>/* w w w  .j  a v a  2s  .com*/

<button onclick="myFunction()">get the number of option elements in the datalist</button>

<p id="demo"></p>

function myFunction() {
    var x = document.getElementById("myDatalist").options.length;
    document.getElementById("demo").innerHTML = "Found " + x + " options in the list.";


Related Tutorials