title: Javascript - dynamically creating an ID for an element -
body: <p>I have some JS in an HTML template. How do I syntax-wise calculate some value, store it in a variable and then use it as the ID for an element? It's not working right now. Can anyone help me figure out what I'm doing wrong?</p>
  
  <pre><code>if (key == "down"){
      var tri_id = "triangle" + status_JSON['down'][1];
      document.getElementById(tri_id).innerHTML = "&lt;img class='voting' src='images/vote_grey.png'&gt;&lt;/img&gt;";
      document.getElementById(status_JSON['down'][1]).innerHTML = status_JSON["down"][0];
  } 
  </code></pre>
  
  <p>DOM is : </p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  var triangle_id = "triangle" + "{{each[1].key()}}";
  &lt;/script&gt;
  &lt;div class='votes_div'&gt;
      &lt;table id="votes_table"&gt;
      &lt;tr&gt;
          &lt;td&gt;
              &lt;a href='javascript:registerVote("{{each[1].key()}}")'&gt;
                  &lt;span id=triangle_id title='vote if you think this review is helpful'&gt;&lt;img class='voting' src='../../../../images/vote_grey.png'&gt;&lt;/img&gt;&lt;/span&gt;
              &lt;/a&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
  </code></pre>
  
  <p>Sorry I'm a a beginner !</p>