jQuery bind inside a for loop variable scope
问题 I know this question has been asked many times but I haven't been able to resolve from what I found on Stack O. Here is my code for(var i=0; i<retrievedSearchesListLength; i++){ retrievedSearchesListProv = retrievedSearchesList[i].searchId; retrievedSearchesListType = retrievedSearchesList[i].searchParameters; function getEventHandlerFunction(a){ $J.cookies.set('ps_clickedsearch',a); } $J('#submitSearch'+i).bind('click',getEventHandlerFunction(retrievedSearchesListType)); } Everytime the