title: JavaScript Getting ID of A Div
body: <p>I have a <code>div</code> box with its <code>id</code> and an <code>textarea</code>.
  When I click on my <code>div</code> box I should get <code>div</code> ID through Javascript and get it printed on the <code>textarea</code>. I have tried but its not working. when I click the text area it says "undefined". Kindly help me.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  
  &lt;script type="text/javascript"&gt;
  function get_id()
  {
      var divEls = document.getElementsByTagName("div");
      var textEl = document.getElementById("mytextarea");
      textEl.value=divEls.id;
  }
  &lt;/script&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div id="mydiv" onclick="get_id()" style='border-width:1px;border-color:#C0C0C0;border-style: solid;background-color:#C0C0C0;width:130px;height:10px;'&gt;
      &lt;/div&gt;
  
      &lt;textarea id="mytextarea"&gt; &lt;/textarea&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>