1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
---|
2 | <html> |
---|
3 | <head> |
---|
4 | <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> |
---|
5 | <title>jQuery 1.3 Adjacent Selector Bug</title> |
---|
6 | <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> |
---|
7 | <script type="text/javascript"> |
---|
8 | var x = $("<button/>") |
---|
9 | .text("click me") |
---|
10 | .click(function() { |
---|
11 | alert("Good job!"); |
---|
12 | }); |
---|
13 | $(function() { |
---|
14 | |
---|
15 | $('li').append(x); |
---|
16 | }); |
---|
17 | </script> |
---|
18 | </head> |
---|
19 | <body> |
---|
20 | <h1>jQuery 1.3 loses event handlers when appending to multiple elements</h1> |
---|
21 | |
---|
22 | <h2>Demo:</h2> |
---|
23 | <ul> |
---|
24 | <li>Hello</li> |
---|
25 | <li>Hello</li> |
---|
26 | <li>Hello</li> |
---|
27 | </ul> |
---|
28 | |
---|
29 | <h2>Code:</h2> |
---|
30 | <pre>$(function() { |
---|
31 | $('li').append($("<button/>") |
---|
32 | .text("click me") |
---|
33 | .click(function() { |
---|
34 | alert("Good job!"); |
---|
35 | }) |
---|
36 | ); |
---|
37 | });</pre> |
---|
38 | |
---|
39 | <h2>Problem:</h2> |
---|
40 | <p>In jQuery 1.2.6, all three buttons would cause an alert box to be shown. In 1.3.1, |
---|
41 | only the first does - the click handler does not appear to get copied to the other buttons. This was filed as bug <a href="http://dev.jquery.com/ticket/4161">#3966</a>, |
---|
42 | (and <a href="http://dev.jquery.com/ticket/4161">ticket #4161</a>) and was supposedly fixed in 1.3.2.</p> |
---|
43 | <p>However, in jQuery 1.3.2, none of the buttons have a click handler!</p> |
---|
44 | <p><a href="./">Back to Browser Bugs</a></p> |
---|
45 | </body> |
---|
46 | </html> |
---|