Skip to content

Instantly share code, notes, and snippets.

@s-hiroshi
Created May 30, 2012 02:38
Show Gist options
  • Save s-hiroshi/2833178 to your computer and use it in GitHub Desktop.
Save s-hiroshi/2833178 to your computer and use it in GitHub Desktop.
JavaScript > pattern > argument to callback function
<div id="hoge">
<p>Foo</p>
<p>Bar</p>
</div>
<div><button id="botton">Click</button></div>
var paragraph = $('#hoge p');
$('#botton').click(function() {
var i;
for (i = 0; i < paragraph.length; i++) {
$(paragraph[i]).animate({
'font-size': 30
}, function(j) {
return function() {
$(paragraph[j]).text(j +': ' + $(paragraph[j]).text());
}
}(i));
}
});
#hoge {
margin: 10px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment