| 1 | <html> |
|---|
| 2 | <head> |
|---|
| 3 | <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script> |
|---|
| 4 | <script type="text/javascript"> |
|---|
| 5 | $(function() { |
|---|
| 6 | // the find() method should return 1 element here but instead returns 0 |
|---|
| 7 | var bug = $("#formId").find("input[name='parent[0].child[0]']"); |
|---|
| 8 | if(bug.length == 0) { |
|---|
| 9 | alert("found a bug. Should have returned 1 element but instead returned 0"); |
|---|
| 10 | } |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | // escaping it doesn't work either |
|---|
| 14 | var escaped = $("#formId").find("input[name='parent\\[0\\]\\.child\\[0\\]']"); |
|---|
| 15 | if(escaped.length == 0) { |
|---|
| 16 | alert("escaping doesn't work either"); |
|---|
| 17 | } |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | var workaround = $("#formId input[name='parent[0].child[0]']"); |
|---|
| 21 | if (workaround.length == 1) { |
|---|
| 22 | alert("the workaround is to use the jQuery method, which properly finds the element"); |
|---|
| 23 | } |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | // strangely enough, one set of brackets works fine |
|---|
| 27 | var oneBracketWorks = $("#formId").find("input[name='parent[0].child']"); |
|---|
| 28 | if (oneBracketWorks.length == 1) { |
|---|
| 29 | alert("strangely enough, using one set of brackets [] works fine"); |
|---|
| 30 | } |
|---|
| 31 | }); |
|---|
| 32 | </script> |
|---|
| 33 | </head> |
|---|
| 34 | <body> |
|---|
| 35 | <form id="formId"> |
|---|
| 36 | <input type="text" name="parent[0].child[0]" /> |
|---|
| 37 | <input type="text" name="parent[0].child" /> |
|---|
| 38 | </form> |
|---|
| 39 | </body> |
|---|
| 40 | </html> |
|---|