title: How to dynamically check and increment div id's in javascript?
body: <p>I have a table of videos that use Longtail Video's JW player.  When you click on an image in the table the video launches in a modal with an id of <code>media modal</code>.  This is the page I'm talking about: <a href="http://www.calvaryccm.com/volunteer/featured-ministry" rel="nofollow">http://www.calvaryccm.com/volunteer/featured-ministry</a>.  </p>
  
  <p>This is the Javascript for the modal:</p>
  
  <pre><code>$(".mediamodal").unbind('click');
  $(".mediamodal").click(function () {
      $('.reveal-modal-bg').unbind('click');
      $('.close-reveal-modal').unbind('click');
      $('#mediamodal').remove();
      $('body').append('&lt;div id="mediamodal" class="reveal-modal large" style="width:675px; margin-left:-415px;"&gt;&lt;div id="mediaplayer"&gt;&lt;script type="text/javascript"&gt;SetupMediaPlayer("' + $(this).attr('rel').toLowerCase() + '");&lt;/script&gt;&lt;/div&gt;&lt;div id="livepoll_min" style="padding-top:20px;"&gt;&lt;/div&gt;&lt;a class="close-reveal-modal"&gt;&amp;#215;&lt;/a&gt;&lt;/div&gt;"');
      $('#mediamodal').reveal({
          animation: 'fadeAndPop',                   //fade, fadeAndPop, none
          animationspeed: 300,                       //how fast animtions are
          closeonbackgroundclick: true,              //if you click background will modal close?
          dismissmodalclass: 'close-reveal-modal'    //the class of a button or element that will close an open modal
      });
      $('.reveal-modal-bg').click(function () {
          $("#mediaplayer").remove();
          socket.disconnect();
      });
  
      $('.close-reveal-modal').click(function () {
          $("#mediaplayer").remove();
          socket.disconnect();
      });
  </code></pre>
  
  <p>This works great on desktop browsers, but not on the iPad.  I looked up why this fails on Longtail's page and they said each needs a unique div id.  I realized that is a problem because I am generating the div onclick.  </p>
  
  <p>How do I change the div id for each video dynamically?</p>