title: How to send a parameter to the each function in Jquery
body: <p>I'm trying to paginate an image gallery using jquery. The image directory I'm using contains about 600 images, named like this: "photo1.jpg" ... "photo(n).jpg" ... "photo600.jpg".</p>
  
  <p>Suppose I have a variable holding the page number <code>var page</code> and there are 40 images on each virtual page. I want to do something like: </p>
  
  <pre><code>for (var i = 0; i&lt;40; i++){
        var imageNum = (((page*40)-40)+i+1);
        $("img")[i].attr("src","photo"+ imageNum + ".jpg"); // Doesn't work
     }
  }
  </code></pre>
  
  <p>This is hackish but do you see what I am trying to do? The jquery API had <a href="http://api.jquery.com/each/" rel="nofollow">some info on using each()</a> to iterate through a jquery object but i couldn't figure out how to send the each function a parameter holding data about which page I am on, which I will need to determine the paths to the images. I'm going for something like:</p>
  
  <pre><code>$("img").each(function (i) {
          //code to update image paths based on page parameter
        });
  </code></pre>
  
  <p>I'm open to different approaches as well, I am a total noob and I feel like I might be going about this in the wrong way to begin with :S. </p>
  
  <p><strong>Edit</strong>
  Thanks to everyone for their answers. </p>
  
  <p>If you are looking for a quick and simple answer that works using each(), check out Jeff B's answer. </p>
  
  <p>I accepted patrick dw's answer because it goes into a bit more detail about a separate mistake I was making and covers another approach as well. Also, please see our comments on his response if you are like me and thought you needed to pass parameters to .each().</p>