title: Cannot read property 'removeChild' of null using JSP
body: <p>I am facing the error "Cannot read property 'removeChild' of null" while populating a list. Here is my code: </p>
  
  <pre><code>       function setTemplates(){
             $.ajax({
                      url:"GetTemplates.jsp",
  
                      success:function(result){
                          //alert("Result Returned:");
                          var myObj = result;
                          myObj= JSON.parse(myObj);
                          alert(myObj.details[0].text);
                          var count =0;
                          var div = document.querySelector("#templates");
                          frag = document.createDocumentFragment();
                          select = document.createElement('select');
                          select.setAttribute('id', 'selectedCodes');
                          select.setAttribute('multiple', '');
                          select.setAttribute("onchange", "GetSelectedCodes()")
                          //select.setAttribute("onchange", "SetWrapUpCode(this.value)")
                          select.setAttribute("class", "list-group checked-list-box");
                          select.setAttribute("size", "7")
                          select.setAttribute("style", "width:270px; clear:both; float:left")
  
                          for(var j=0; j&lt;myObj.names.length; j++)
                          {
                              //alert(myObj.names[j].name)
                              select.options.add( new Option(myObj.names[j].name, myObj.names[j].name, true, true) );
  
                          }
  
                          frag.appendChild(select);
                          div.removeChild(div.childNodes[0]);
                          div.appendChild(frag);
  
  
                      }
                  });
     }
  </code></pre>
  
  <p>here is my HTML Code:</p>
  
  <pre><code>  &lt;div class="col-md-5"&gt;
          &lt;h3&gt;Templates&lt;/h3&gt;
             &lt;div class="well"&gt;
                 &lt;form id="templates"&gt;
                 &lt;/form&gt;
             &lt;/div&gt;
    &lt;/div&gt;
  </code></pre>
  
  <p>Here is my JSP code </p>
  
  <pre><code> &lt;%
   TemplateClient templates = new TemplateClient();
   JSONObject templateResponse = new JSONObject();
   templateResponse = templates.getResponse(); 
   out.print(templateResponse);
   out.flush();
   %&gt;
  </code></pre>
  
  <p>I am using NetBeans for this. Please help me to sort out this issue. </p>