| 1 | <!DOCTYPE html> |
|---|
| 2 | <body> |
|---|
| 3 | <form id="f" action="."> |
|---|
| 4 | <div> |
|---|
| 5 | <select id="s"> |
|---|
| 6 | <option value="1">Option 1</option> |
|---|
| 7 | <option value="2">Option 2</option> |
|---|
| 8 | </select> |
|---|
| 9 | </div> |
|---|
| 10 | </form> |
|---|
| 11 | <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> |
|---|
| 12 | <script> |
|---|
| 13 | var emptyCollection = jQuery(); |
|---|
| 14 | |
|---|
| 15 | var selectElement = document.getElementById("s"); |
|---|
| 16 | var selectResults = []; |
|---|
| 17 | |
|---|
| 18 | var formElement = document.getElementById("s"); |
|---|
| 19 | var formResults = []; |
|---|
| 20 | |
|---|
| 21 | // These should be equivalent: |
|---|
| 22 | selectResults[0] = emptyCollection.add(selectElement); |
|---|
| 23 | selectResults[1] = emptyCollection.add("#s"); |
|---|
| 24 | selectResults[2] = emptyCollection.add(jQuery(selectElement)); |
|---|
| 25 | |
|---|
| 26 | // These should also be equivalent: |
|---|
| 27 | formResults[0] = emptyCollection.add(formElement); |
|---|
| 28 | formResults[1] = emptyCollection.add("#f"); |
|---|
| 29 | formResults[2] = emptyCollection.add(jQuery(formElement)); |
|---|
| 30 | |
|---|
| 31 | if (testBug(selectResults, "select") && testBug(formResults, "form")) { |
|---|
| 32 | alert("Test passed."); |
|---|
| 33 | } else { |
|---|
| 34 | alert("Test failed."); |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | function testBug(results, tagName) { |
|---|
| 38 | for (var i = 0; i < results.length; i++) { |
|---|
| 39 | if (results[i].not(tagName).length > 0) { |
|---|
| 40 | return false; |
|---|
| 41 | } |
|---|
| 42 | } |
|---|
| 43 | return true; |
|---|
| 44 | } |
|---|
| 45 | </script> |
|---|
| 46 | </body> |
|---|