Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
michael@0 | 1 | <!DOCTYPE html> |
michael@0 | 2 | <html> |
michael@0 | 3 | <select style="position: relative" size=4> |
michael@0 | 4 | <option>bar</option> |
michael@0 | 5 | </select> |
michael@0 | 6 | <select style="position: relative"> |
michael@0 | 7 | <option>bar</option> |
michael@0 | 8 | </select> |
michael@0 | 9 | <script> |
michael@0 | 10 | function injectAbsPosKid(s) { |
michael@0 | 11 | var option = document.createElement("option"); |
michael@0 | 12 | option.appendChild(document.createTextNode("foo")); |
michael@0 | 13 | option.style.position = "absolute"; |
michael@0 | 14 | option.style.top = "100px"; |
michael@0 | 15 | s.insertBefore(option, s.firstChild); |
michael@0 | 16 | |
michael@0 | 17 | var div = document.createElement("div"); |
michael@0 | 18 | div.appendChild(document.createTextNode("bar")); |
michael@0 | 19 | div.style.position = "absolute"; |
michael@0 | 20 | div.style.top = "200px"; |
michael@0 | 21 | s.appendChild(div); |
michael@0 | 22 | } |
michael@0 | 23 | onload = function() { |
michael@0 | 24 | var s1 = document.querySelectorAll("select")[0]; |
michael@0 | 25 | var s2 = document.querySelectorAll("select")[1]; |
michael@0 | 26 | injectAbsPosKid(s1); |
michael@0 | 27 | injectAbsPosKid(s2); |
michael@0 | 28 | s2.selectedIndex = 0; |
michael@0 | 29 | }; |
michael@0 | 30 | </script> |
michael@0 | 31 | </html> |