Skip to content

Instantly share code, notes, and snippets.

@mdales
Created May 17, 2010 13:33
Show Gist options
  • Save mdales/403761 to your computer and use it in GitHub Desktop.
Save mdales/403761 to your computer and use it in GitHub Desktop.
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>closuretest</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js">
</script>
<script>
var list = [
{name: 'foo', val: 42},
{name: 'bar', val: 32}
];
function setclick(obj)
{
$("button#" + obj.name).click(function()
{
console.log(obj);
}
);
}
$(document).ready(function()
{
var idx;
for (idx in list)
{
var info = list[idx];
$("#testarea").append('<button id="' + info.name + '">Test</button>');
setclick(info);
}
}
);
</script>
</head>
<body id="closuretest">
<div id="testarea">
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment