Skip to content

Instantly share code, notes, and snippets.

@geoffb
Created February 15, 2011 22:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geoffb/828463 to your computer and use it in GitHub Desktop.
Save geoffb/828463 to your computer and use it in GitHub Desktop.
<!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