title: JavaScript Adding an ID attribute to another created Element
body: <p>I have some code here that will do the following. The code creates an element "p" then I append it to a "div" in the HTML. I would like that "p" I just created have an unique identifier (ID) and set the name of the ID. So later on when the user wants to delete the last created element it will be able to get the ID so it can removeChild. Here is the code:</p>
  
  <p>JavaScript:</p>
  
  <pre><code>  var $ = function (id)
    {
        return document.getElementById(id);
    }
  
    function ShowResponse ()
    {
    var myResponse = $("myresponse").value;
  
    var myPara = document.createElement("p");
    var myDiv = $("mydiv");
    myDiv.appendChild(myPara);
  
    var myID = document.createElement("id");
    myID.setAttribute("value", ID)
  
    var myText = document.createTextNode(myResponse);
    myPara.appendChild(myText);
    }
  
    function RemoveResponse ()
    {
  
    }
  
    window.onload = function ()
    {
        $("showresponse").onclick = ShowResponse;
        $("removeresponse").onclick = RemoveResponse;
    }
  </code></pre>
  
  <p>HTML:</p>
  
  <pre><code>  &lt;body&gt;
    &lt;div id="mydiv"&gt;
    &lt;h1&gt;Practice&lt;/h1&gt;
  
    &lt;p&gt;Hi There&lt;/p&gt;
    &lt;p&gt;How are you?&lt;/p&gt;
  
    &lt;p&gt;
  &lt;input type="text" id="myresponse"&gt;
  &lt;br&gt;&lt;input type="button" id="showresponse" value="Show Response"&gt;
  &lt;input type="button" id="removeresponse" value="Remove Response"&gt;
    &lt;/p&gt;
  
    &lt;hr&gt;
   &lt;/div&gt;
  
   &lt;/body&gt;
  </code></pre>