Created
February 15, 2011 22:58
-
-
Save geoffb/828463 to your computer and use it in GitHub Desktop.
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 lang="en"> | |
<head> | |
<title>jQuery Event Test</title> | |
<style> | |
.red { | |
background: #f00; | |
} | |
.blue { | |
background: #00f; | |
} | |
</style> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script> | |
</head> | |
<body> | |
<div id="container"> | |
<div class="red">Red DIV</div> | |
<div class="blue">Blue DIV</div> | |
</div> | |
<script> | |
var bind = function (fn, context) { | |
return function () { | |
fn.apply(context, arguments); | |
} | |
}; | |
var lib = {}; | |
lib.MyObject = function (name) { | |
this.name = name; | |
this.container = $("#container"); | |
this.container.click(bind(this.handleClick, this)); | |
}; | |
lib.MyObject.prototype.handleClick = function (e) { | |
var target = $(e.target); | |
alert(this.name + " says: You clicked " + target.html()); | |
}; | |
var foo = new lib.MyObject("Geoff"); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment