title: Creating and removing <div> element in Javascript
body: <pre><code>function labelOnClick () {
      function makeDivId(id) {
          return id + "_div";
      };
  
      var div = this.getElementById(makeDivId(this.id));
  
      if (div) {
          div.parentNode.removeChild(div);
      } else {
          div = document.createElement("div");
          div.innerHTML = "welcome";
          div.id = makeDivId(this.id);
  
          this.appendChild(div);
      }
  }
  
  
  
  
  &lt;label id="1" onclick="labelOnClick()" &gt; BROWSER &lt;/label&gt;
  &lt;label id="2" onclick="labelOnClick()"&gt; GAMING CONSOLE &lt;/label&gt;
  </code></pre>
  
  <p>In the above example, I'm trying to create a <code>div</code> element when a label is clicked and remove the created <code>div</code> element when the label is clicked again, but it's not working. </p>