title: Register onclick events from dynamically created div array? Rails + Jquery?
body: <p>After <a href="https://stackoverflow.com/questions/9971879/link-to-remote-true-causing-strange-routing-problems-rails-3/9971988#comment12740780_9971988">failing to achieve this</a> with link_to remote, I decided to try jQuery way. 
  Here is the jQuery loop and the rails loop and how they interact. Problem is I getting to register clicks only on one of the div's out of each loop, so the thing is not really working.. Here is the code:</p>
  
  <pre><code>&lt;% @node.parent_relation.videos.each_with_index do |vid, idx| %&gt;
    &lt;%=  image_tag("http://img.youtube.com/vi/#{vid.content}/1.jpg", :id  =&gt; "img_div_#{idx}") %&gt;
    &lt;div id="vid_vid_&lt;%=idx%&gt;"  style="display: none"&gt; &lt;%= vid.id %&gt;&lt;/div&gt;
  &lt;% end %&gt;
  
    &lt;script&gt;
    var ids = "&lt;%= @node.parent_relation.videos.length %&gt;";
    var div_arr = [];
    var img_arr = [];
    var vid_id = 0;
    for( i=0; i &lt; parseInt(ids); i++){
      var x = String("vid_vid_"+String(i));
      var y = String("img_div_"+String(i));
      div_arr.push(x);
      img_arr.push(y);
    }
    for ( i=0; i &lt; parseInt(ids); i++){
      var vst = '#'+String(img_arr[i]);
      var dst = '#'+String(div_arr[i]);
      $(function() {
        $(vst).click(function(){
          var vid_id = $(dst).html();
          console.log(vid_id);
          $.post("/nodes/iframize/", {video_id: vid_id});
        });
      })
  
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>And there is an iframize action in nodes controller and an js.erb that updates the div from respond_to format.js in that action, that part works.. </p>
  
  <p>Thanks a lot, any advise greatly appreciated..</p>