title: variable undefined when using alert()
body: <pre><code>I have this script:
  
  &lt;script&gt;
  
  var prop = document.getElementById('div1').firstChild.getAttribute("id");
  
  function aler()
  {
      alert(prop);
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>and out of the script tag:</p>
  
  <pre><code>&lt;div id="div1"&gt;some content&lt;/div&gt;
  &lt;button onclick="aler()"&gt;&lt;/button&gt;
  </code></pre>
  
  <p>Can someone explain to me why when I click the button it says: "undefined"</p>
  
  <p>Correction:
  in the div i drag a picture:</p>
  
  <pre><code>  &lt;img  id="C" src="C.png"  draggable="true" ondragstart="drag(event)" width="91px" height="91px"&gt;
  </code></pre>
  
  <p>for example.</p>