title: Is it possible to dynamically create these jQuery click handlers?
body: <p>I need to create click handlers for several HTML buttons that control an image gallery.  Each of the buttons in the HTML receive a class that indicates which function to perform - such as step forward or step backward.  I also need to create these handlers for multiple galleries on the same web page.</p>
  
  <p>This is the "hard coded" version. Is it possible to create a dynamic function(s) to replicate this working example below?</p>
  
  <pre><code>$('.gallery0_stepForward').on('click', function() {
      gallery_changeImage(0, 1);    // step gallery 0 forward 1 image
      gallery_stopAutoTimer(0);     // stop the automatic slide show
  });
  </code></pre>
  
  <p>I have attempted something like this:</p>
  
  <pre><code>for (i=0;i&lt;5; i++){   // 5 galleries in this example
  
      var target = ".gallery" + i + "_stepForward";
      var fnName = "stepForward" + i;
  
      function setFunc ( fnName ) {
          this[ fnName ] = function() {
                  console.log('hello ' + fnName);
                  gallery_changeImage(i, 1);
          gallery_stopAutoTimer(i);
             };
      }
  
      $(target).on('click', fnName);
  }
  </code></pre>
  
  <p>The system of attaching classes to the HTML must remain. The function "gallery_changeImage(val,val)" must remain as there are multiple lines of code in that function. Thank you.</p>