select-add.html (1177B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>HTMLSelectElement Test: add()</title> 4 <link rel="author" title="Intel" href="http://www.intel.com/"> 5 <link rel="help" href="https://html.spec.whatwg.org/multipage/form-elements.html#dom-select-add-dev"> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 9 <form style="display:none"> 10 <option id="testoption"> 11 <select id="testselect1"> 12 </select> 13 <select id="testselect2"> 14 <option>TEST</option> 15 </select> 16 </option> 17 </form> 18 19 <script> 20 21 test(() => { 22 let testselect1 = document.getElementById("testselect1"); 23 let opt1 = new Option("Marry","1"); 24 testselect1.add(opt1); 25 assert_equals(testselect1.options[0].value, "1"); 26 }, "test that HTMLSelectElement.add method can add option element"); 27 28 test(() => { 29 let testselect2 = document.getElementById("testselect2"); 30 let opt2 = document.getElementById("testoption"); 31 assert_throws_dom("HierarchyRequestError", () => { 32 testselect2.add(opt2); 33 }); 34 }, "test that HierarchyRequestError exception must be thrown when element is an ancestor of the element into which it is to be inserted"); 35 36 </script>