次のコードを実行すると、同じ要素IDが2回アラートされると予想されますが、代わりに、最初のコードは正しいのに対し、2番目のコードは常にセットの最初の要素の名前を示しています。
$("div.someClass").each(function (index) {
$(this).click(function () {
alert($(this).attr("id")); // Here i get the actually clicked element
$.when($("div.someClass").animate({ }, 0)).then(function () {
alert($(this).attr("id")); // Here i get the first element in of that class
});
});
});
なんでそうなの?それを解決する方法は?要素の名前を関数に渡そうとしましたが、機能しませんでした。