title: How to give id names to <input> and selector values dynamically
body: <p>I am currently looping through a list and appending that information as follows. I want to use the 'ID' information from that list and send that information to a url every time I press the 'Paid' button. This works currently when I hard code the selector as '#input1' and id value as identity[0]. </p>
  
  <p>This would not work if I were to have a second set of information with a new id and a new button that goes along with it cos during append, the 2nd button will also be of id input1.</p>
  
  <p>Is there a way to dynamically give different id names to the button each time it loops, pair it up with the list id number and a way to give info to the selector depending on which button is pressed?   </p>
  
  <p>Or is there a better way to do this? Please advice. Thanks. </p>
  
  <pre><code>var identity = [];
  var count = 0;
  
  $.getJSON("http://website.com/public/user/listunpaidbills/",function(data){
          //Loop for each element on the data
          $.each(data,function(elem){
              var wrap = $("&lt;div/&gt;").attr('data-role', 'collapsible');
              count++;
              identity.push(data[elem].id); 
              //Create the h1 and the other elements appending them to bills List
              $("&lt;h1/&gt;",{
                  text:data[elem].reference
              }).appendTo(wrap);   
              $("&lt;p/&gt;",{
                  text:"Account: "+ data[elem].account
              }).appendTo(wrap);        
              $("&lt;p/&gt;",{
                  text:"Amount: "+ data[elem].amount
              }).appendTo(wrap);
              $("&lt;input type='submit' value='Paid' id='input1'/&gt;",{
                  text:"Paid"
              }).appendTo(wrap);
              wrap.appendTo('#unpaidList');             
          })//end of for each loop 
          $( "#unpaidList" ).collapsibleset( "refresh" );
      })
  
          $("#input1").click(function(){
            $.getJSON("http://website.com/public/user/confirmbill/", {
                  id: identity[0] 
                  }, function(data) {
                      alert(data.status);
                  }).fail(function() {
                      alert("error");
              })
          });
  </code></pre>