how to remove the append child element in javascript
<pre><code>&lt;label id="1" &gt;a&lt;/label&gt;&lt;label id="2" &gt; b &lt;/label&gt;
</code></pre>

<p>I have two labels created. When a label is clicked, I create a <code>div</code> element within that I displayed. Now I need to remove the created <code>div</code> element if the label is again clicked.</p>

<pre><code>if (click == 1) {
    var prevWin = document.createElement("div");
    prevWin.id = 1;
    prevWin.innerHTML = outMsg;
    document.body.appendChild(prevWin);
} else {
    var prevWin = document.body.getElementsById(1);
    document.body.removeChild(prevWin);
}
</code></pre>

<p>When a label is clicked the <code>div</code> element is created successfully. But when it is clicked again, the <code>div</code> element is not removed.</p>
