Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<!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
You can’t perform that action at this time.