Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /html/semantics/forms/the-select-element/select-selectedOptions-and-selected.html - WPT Dashboard Interop Dashboard
<!doctype html>
<meta charset="utf-8">
<title>HTMLSelectElement's selectedOptions and HTMLOptionElement's selected</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<select id="sel">
<option id="opt1" value="x" data-foo="a" selected="selected">1st opt</option>
<option id="opt2" value="y" data-foo="b">2nd opt</option>
</select>
<script>
"use strict";
test(() => {
const select = document.getElementById("sel");
const opt1 = document.getElementById("opt1");
assert_equals(select.selectedOptions.length, 1);
assert_equals(select.selectedOptions[0], opt1);
});
</script>