title: Updating dynamically created DIVs using Ajax / Django
body: <p>I was really trying to avoid making the title too ambiguous, but I wasn't quite sure how else to phrase it (as a result of being such a web development noob). </p>
  
  <p>Here is the scenario, I have a template created that loops through a list of objects, each with a unique id. Let's call these objects "clocks" for the example. I've trimmed the template code to the bare minimum for simplicity. </p>
  
  <pre><code>{% for clock in clock_list %}
      &lt;div id="clock_{{ clock.id }}"&gt;&lt;/div&gt;
  {% endfor %}
  </code></pre>
  
  <p>Each of these DIVs should display a timer/clock of sorts, unique to that specific clock. And each one should be incrementing every second on the page (there will be at most 10 clocks running on the page). </p>
  
  <p>Now I've spent a good deal trying to grasp how to use AJAX for this (and feel free to tell me of any simpler / more efficient alternatives), but I'm not sure if I'm understanding how AJAX works properly. How might I be able to update each of these dynamically created div's independently (or at least have them all update on the same "setTimeout(function(),1000)" duration. </p>
  
  <p>Below is the code I was referencing for AJAX:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  function Ajax(){
  
      var xmlHttp = new XMLHttpRequest();
  
      xmlHttp.onreadystatechange=function(){
          if(xmlHttp.readyState==4){
              document.getElementById('element_id').innerHTML=xmlHttp.responseText;
              setTimeout('Ajax()',1000);
          }
      }
  xmlHttp.open("GET","content.html",true);
  xmlHttp.send(null);
  }
  
  window.onload=function(){
  setTimeout('Ajax()',1000);
  }
  </code></pre>
  
  <p></p>
  
  <p>I'm assuming the idea would be to use "clock_{{ vice.id }}" for the "document.getElementById('element_id').innerHTML=xmlHttp.responstText;" portion, but how can I use django's template for loops to move through and obtain the contents of a "clock.html" file that contains the contents of the div. </p>
  
  <p>If anybody is willing to help out and needs more details please say so. For the time being I'll continue with this bumpercar programming until I have something to show for it :).</p>