| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
|---|
| 2 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
|---|
| 3 | <html xmlns="http://www.w3.org/1999/xhtml"> |
|---|
| 4 | <head> |
|---|
| 5 | <title>:checked Bug</title> |
|---|
| 6 | <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> |
|---|
| 7 | <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script> |
|---|
| 8 | <script type="text/javascript"> |
|---|
| 9 | $(document).ready(function() { |
|---|
| 10 | |
|---|
| 11 | // Duplicate <div class="boxes"> ... |
|---|
| 12 | $("a.inserter").click(function(e) { |
|---|
| 13 | e.preventDefault(); |
|---|
| 14 | $(this).next().clone().appendTo("#root"); |
|---|
| 15 | $("a.counter").click(); // ... and update the counter |
|---|
| 16 | }); |
|---|
| 17 | |
|---|
| 18 | // Count all elements :checked inside the document: |
|---|
| 19 | $("a.counter").click(function(e) { |
|---|
| 20 | e.preventDefault(); |
|---|
| 21 | $("span.result").text($(":checked").length); |
|---|
| 22 | }); |
|---|
| 23 | |
|---|
| 24 | // Prefill the counter |
|---|
| 25 | $("a.counter").click(); |
|---|
| 26 | }); |
|---|
| 27 | </script> |
|---|
| 28 | </head> |
|---|
| 29 | |
|---|
| 30 | <body> |
|---|
| 31 | <div id="root"> |
|---|
| 32 | <pre><a class="counter" href="#">$(":checked").length</a>: <strong><span class="result">-</span></strong></pre><br /> |
|---|
| 33 | <a class="inserter" href="#">Duplicate <div> with checkboxes and radiobuttons</a> |
|---|
| 34 | |
|---|
| 35 | <div class="boxes"> |
|---|
| 36 | <hr /> |
|---|
| 37 | <form> |
|---|
| 38 | <input type="checkbox" name="c1" value="a" checked="checked" /> A<br /> |
|---|
| 39 | <input type="checkbox" name="c1" value="d" checked="checked" /> B<br /> |
|---|
| 40 | <br /> |
|---|
| 41 | <input type="radio" name="r1" value="1" checked="checked" /> 1<br /> |
|---|
| 42 | <input type="radio" name="r1" value="2" /> 2<br /> |
|---|
| 43 | </form> |
|---|
| 44 | </div> |
|---|
| 45 | |
|---|
| 46 | </div> |
|---|
| 47 | </body> |
|---|
| 48 | </html> |
|---|