HTMLInputElement: list property
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2019.
Thelist read-only property of theHTMLInputElement interface returns theHTMLDataListElement pointed to by thelist attribute of the element, ornull if thelist attribute is not defined or thelist attribute's value is not associated with any<datalist> in the same tree.
Note:This is a read-only property. To associate a<datalist> with an element, set the value of thelist attribute withsetAttribute().
In this article
Value
AnHTMLDataListElement ornull.
Example
Given the following HTML:
html
<label for="planet">Which planet are you from?</label><input type="text" list="superhero" /><datalist> <option value="Azarath"></option> <option value="Krypton"></option> <option value="Tamaran"></option></datalist>You can retrieve the<datalist> element associated with the<input>:
js
const inputElement = document.querySelector("#planet");console.log(inputElement.list); // returns the superhero HTMLDatalistElementSpecifications
| Specification |
|---|
| HTML> # dom-input-list-dev> |