Browse files

Tweaking the game to use delegate instead of live.

  • Loading branch information...
1 parent 0d50641 commit 1dc786d99e15bae30aeb3b4627f54849cf413960 @jeresig committed Mar 4, 2010
Showing with 8 additions and 8 deletions.
  1. +8 −8 adv-talk/game-done.html
View
16 adv-talk/game-done.html
@@ -9,12 +9,12 @@
$(function(){
var score = 0, life = 100;
- $(".user").live("hit", function(){
+ $("#game").delegate(".user", "hit", function(){
var data = $(this).data();
data.hits++;
if ( data.hits >= data.maxhits ) {
- $(this).stop().detach();
+ $(this).stop().remove();
} else {
$(this).addClass("hit");
}
@@ -23,7 +23,7 @@
$("#score").text( score );
});
- $(".user").live("escape", function(){
+ $("#game").delegate(".user", "escape", function(){
var data = $(this).data();
life -= data.maxhits * 3;
@@ -39,11 +39,7 @@
$("#game").trigger("stop");
}
- $(this).detach();
- });
-
- $("input").click(function(){
- $("#game").trigger("start");
+ $(this).remove();
});
$("#game").bind("start", function(){
@@ -62,6 +58,10 @@
$("#game").bind("stop", function(){
$("input").show();
});
+
+ $("input").click(function(){
+ $("#game").trigger("start");
+ });
});
</script>
</head>

0 comments on commit 1dc786d

Please sign in to comment.