Skip to content

Commit

Permalink
New page: HTMLInputElement.list (#35625)
Browse files Browse the repository at this point in the history
* New page: HTMLInputElement.list

* Update files/en-us/web/api/htmlinputelement/list/index.md

Co-authored-by: Joshua Chen <[email protected]>

* Update files/en-us/web/api/htmlinputelement/list/index.md

Co-authored-by: Joshua Chen <[email protected]>

* Update files/en-us/web/api/htmlinputelement/list/index.md

Co-authored-by: Joshua Chen <[email protected]>

* Update files/en-us/web/api/htmlinputelement/list/index.md

* Update files/en-us/web/api/htmlinputelement/list/index.md

* Update files/en-us/web/api/htmlinputelement/list/index.md

---------

Co-authored-by: Joshua Chen <[email protected]>
  • Loading branch information
estelle and Josh-Cena authored Aug 28, 2024
1 parent 1fc3cc6 commit 46bcde6
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions files/en-us/web/api/htmlinputelement/list/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
title: "HTMLInputElement: list property"
short-title: list
slug: Web/API/HTMLInputElement/list
page-type: web-api-instance-property
browser-compat: api.HTMLInputElement.list
---

{{ApiRef("HTML DOM")}}

The **`list`** read-only property of the {{domxref("HTMLInputElement")}} interface returns the {{domxref("HTMLDataListElement")}} pointed to by the [`list`](/en-US/docs/Web/HTML/Element/input#list) attribute of the element, or `null` if the `list` attribute is not defined or the `list` 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 the `list` attribute with {{domxref("Element.setAttribute", "setAttribute()")}}.
## Value

An {{domxref("HTMLDataListElement")}} or `null`.

## Example

Given the following HTML:

```html
<label for="planet">Which planet are you from?</label>
<input id="planet" type="text" list="superhero" />
<datalist id="superhero">
<option value="Azarath" />
<option value="Krypton" />
<option value="Tamaran" />
</datalist>
```

You can retrieve the `<datalist>` element associated with the `<input>`:

```js
const inputElement = document.querySelector("#planet");
console.log(inputElement.list); // returns the superhero HTMLDatalistElement
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- {{domxref("HTMLInputElement.value")}}
- {{domxref("HTMLInputElement.type")}}
- {{domxref("HTMLDataListElement")}}
- {{domxref("HTMLOptionElement")}}
- {{domxref("HTMLCollection")}}
- {{htmlelement("input")}}
- {{htmlelement("datalist")}}
- {{htmlelement("option")}}

0 comments on commit 46bcde6

Please sign in to comment.