astralaaron Posted February 2, 2016 Share Posted February 2, 2016 Hello, I'm having a bit of trouble with jquery. I have something similar to the following: function someFunction( i ){ for(var x = 0; x < numOfPosts; x++) { var callbackA = function() { console.log('set i=' + i + ' x=' + x); }; var callbackB = function() { console.log('set i=' + i + ' x=' + x); }; $( element ).hover( callbackA , callbackB ); } } The issue I am having is that x is always equal to the "numOfPosts" for each iteration. Anything obvious that I am doing incorrectly? Thanks everyone for reading. Link to comment Share on other sites More sharing options...
astralaaron Posted February 2, 2016 Author Share Posted February 2, 2016 I was able to fix this by creating a function with the jquery inside it, passed the i/x parameters in to that function and it works. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now