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-value.html - WPT Dashboard Interop Dashboard
<!doctype html>
<meta charset="utf-8">
<title>HTMLSelectElement.selectedOptions and HTMLSelectElement.value</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<select id="sel">
<option id="opt1" value="x" data-foo="a">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");
const opt2 = document.getElementById("opt2");
select.value = "x";
assert_equals(select.selectedOptions[0], opt1);
select.value = "y";
assert_equals(select.selectedOptions[0], opt2);
}, "`HTMLSelectElement.selectedOptions` is correctly updated when `HTMLSelectElement.value` changes");
</script>