Created
March 7, 2012 00:26
-
-
Save safe1981/1990077 to your computer and use it in GitHub Desktop.
Javascript: Event handler using jQuery(bind,on,live,delegate)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<meta charset=utf-8> | |
<title>jQuery Events 201</title> | |
<link rel="stylesheet" href="style.css"> | |
</head> | |
<body> | |
<h2>Click me</h2> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> | |
<script> | |
(function(){ | |
$('h2').click(function(){ | |
console.log("clicked"); | |
$(this).clone(true).appendTo('body'); | |
}); | |
$('h2').bind('click',function(){ | |
console.log("clicked"); | |
$(this).clone(true).appendTo('body'); | |
}); | |
$('h2').on('click', function(){ | |
console.log("clicked"); | |
$(this).clone(true).appendTo('body'); | |
}); | |
$('h2').live('click', function(){ | |
console.log("clicked"); | |
$(this).clone().appendTo('body'); | |
}); | |
$('body').delegate('h2', 'click', function(){ | |
console.log("clicked"); | |
$(this).clone().appendTo('body'); | |
}); | |
})(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment