Bug Tracker

Ticket #4894: die_bug.txt

File die_bug.txt, 912 bytes (added by Leeoniya, 11 years ago)
Line 
1-----HTML-------
2<p id="a"><span>This has a over highlight style and event 'click'.</span></p>
3<p><a id="b" href="#">Click here to erase the click event in the last paragraph's inner span</a></p> 
4
5------JS--------
6// without event delegation -- works fine
7$(function() {
8        $("#b").click(function() {
9                $("#a span").unbind("click");
10                return false;
11        });
12
13        $("#a span").hover(
14                function() {$(this).addClass("high");},
15                function() {$(this).removeClass("high");}
16        ).click(function() {
17                $(this).append(" He. ");
18        });
19});
20
21// with event delegation - .die("click") kills all live events
22$(function() {
23        $("#b").live("click", function() {
24                $("#a span").die("click");
25                return false;
26        });
27
28        $("#a span")
29        .live("mouseover", function() {$(this).addClass("high");})
30        .live("mouseout", function() {$(this).removeClass("high");})
31        .live("click", function() {$(this).append(" He. ");});
32});