Bug Tracker

Ticket #4161: jquery-1.3.1-append-handlers.html

File jquery-1.3.1-append-handlers.html, 1.4 KB (added by dalangalma, 14 years ago)

Demo of the bug

Line 
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.1/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        $('li').append(x);
15      });   
16    </script>
17        </head>
18        <body>
19          <h1>jQuery 1.3 loses event handlers when appending to multiple elements</h1>
20   
21    <h2>Demo:</h2>
22    <ul>
23      <li>Hello</li>
24      <li>Hello</li>
25      <li>Hello</li>
26    </ul>
27   
28    <h2>Code:</h2>
29    <pre>$(function() {
30  $('li').append($("&lt;button/&gt;")
31    .text("click me")
32    .click(function() {
33      alert("Good job!");
34    })
35  );
36});</pre> 
37   
38    <h2>Problem:</h2>
39    <p>In jQuery 1.2.6, all three buttons would cause an alert box to be shown. In 1.3.1,
40    only the first does - the click handler does not appear to get copied to the other buttons.</p>
41    <p>This is <a href="http://dev.jquery.com/ticket/4161">ticket #4161</a>.</p>
42    <p><a href="./">Back to Browser Bugs</a></p>
43        </body>
44</html>