Removing every child element EXCEPT first child?
To remove all but the first child:
while (cntnt.childNodes.length > 1) {
cntnt.removeChild(cntnt.lastChild);
}
You could also filter by the id
of the select
you want to save
while (cntnt.lastChild.id !== 'pSort') {
cntnt.removeChild(cntnt.lastChild);
}
Or your could just get the innerHTML
of pSort
and append it with the ajax response right away, without having to loop to remove elements
cntnt.innerHTML = document.getElementById('pSort').innerHTML + return_data;