title: Removing every child element EXCEPT first child?
body: <pre><code>function sortPosts() {
  var pSort = document.getElementById('pSort').selectedIndex;
  var pstSort = document.getElementById('pSort').options;
  var sorted = pstSort[pSort].value;
  var hr = new XMLHttpRequest();
  var url = "...";
  var vars = "sort="+sorted;
  hr.open("POST", url, true);
  hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  hr.onreadystatechange = function() {
      if (hr.readyState === 4 &amp;&amp; hr.status === 200) {
          var return_data = hr.responseText;
          var cntnt = document.getElementById('content');
          while ((cntnt.lastChild !== '
           &lt;select id="pSort"&gt;
            &lt;option value="all" selected="true"&gt;All Posts&lt;/option&gt;
            &lt;option value="friends"&gt;Friends\' Posts&lt;/option&gt;
            &lt;option value="following"&gt;Following\'s Posts&lt;/option&gt;&lt;/select&gt;' &amp;&amp; cntnt.childNodes.length !== 1) || (cntnt.firstChild != '&lt;select id="pSort"&gt;&lt;option value="all" selected="true"&gt;All Posts&lt;/option&gt;&lt;option value="friends"&gt;Friends\' Posts&lt;/option&gt;&lt;option value="following"&gt;Following\'s Posts&lt;/option&gt;&lt;/select&gt;' &amp;&amp; cntnt.childNodes.length != 1)) {
              cntnt.removeChild(cntnt.lastChild);
          }
          document.getElementById('content').innerHTML += return_data;
          document.getElementById('content').style.opacity = '1.0';
      }
  }
  hr.send(vars);
  document.getElementById('content').style.opacity = "0.5";
  </code></pre>
  
  <p>}</p>
  
  <p>I need to remove every child element in the div#content element until only the select element remains. I would say every child element except the first, but it seems there's an invisible text node in Chrome within the div#content element that I have no control over.</p>
  
  <p>Or if you have a better way to keep the select element on the page while ajax loads new content and removes the old content, I'd love to hear it.</p>