Latest web development tutorials

Datalist options collection

Datalist Object Reference Datalist objects

Examples

Datalist controls through all the options and output options value:

var x = document.getElementById ( "mySelect");
var txt = "";
for (var i = 0; i <x.options.length; i ++)
{
txt = txt + x.options [i] .value + "<br>";
}

txt output is:

Internet Explorer
Firefox
Chrome
Opera
Safari

try it"

Definitions and use

options set datalist collection returns all options.

Note: Sorting a collection of elements by elements in the code position sorting.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support options set.


grammar

datalistObject .options

Attributes

Property description
length Returns the number of elements in the collection options

method

method description
[Index] An integer that specifies the element to retrieve (starting from 0)
item(index) Returns the specified index from the collection element (starting from 0)
namedItem(name_or_id) From the collection with the specified name (name or id attribute) returns the element


More examples

Examples

Datalist show the number of elements:

var x = document.getElementById ( "browsers") options.length.;

x The output is:

5

try it"

Examples

[Index]

Return Value datalist first option (index 0) is:

var x = document.getElementById ( "browsers") options [0] .value.;

x The output is:

Internet Explorer

try it"

Examples

item (index)

Return Value datalist first option (index 0) is:

. Var x = document.getElementById ( "browsers") options.item (0) .value;

x The output is:

Internet Explorer

try it"

Examples

namedItem (name_or_id)

Back id = "google" value datalist options:

var x = document.getElementById ( "browsers") options.namedItem ( "google") value..;

x The output is:

Chrome

try it"


Datalist Object Reference Datalist objects