title: Javascript Pass Element ID Attribute as Parameter
body: <p>This statement works. On the click of the node, i get a message displaying its ID.</p>
  
  <pre><code> newnode.setAttribute("onClick", "alert(this.id)"); 
  </code></pre>
  
  <p>I need to pass the value of <em>this.id</em> to a different function and am struggling to get around it.</p>
  
  <p>Attempt 1:</p>
  
  <p>The below does not work; I understand that i cant pass <strong>this.id</strong> to another function, which does the same thing, because <strong>this</strong> is not relevant to anything within the test function:</p>
  
  <pre><code>newnode.setAttribute("onClick", "test(this.id)"); 
  
  function test(f){
  alert(f);
  }
  </code></pre>
  
  <p>Attempt 2:</p>
  
  <pre><code>var testvar = newnode.id;
  newnode.setAttribute("onClick", "test(testvar)"); 
  
  function test(f){
  alert(f);
  }
  </code></pre>
  
  <p>Why is <em>testvar</em> not recognised in my setAttribute line?</p>