I've this code:
<p>     <span> text </span>     </p>
how to delete second and third   of p, through the node span?
Get child nodes of p
and remove space from text nodes
var p = document.getElementsByTagName('p')[0];
var nodes = p.childNodes;
nodes[0].textContent = nodes[0].textContent.replace(' ', '');
nodes[2].textContent = nodes[2].textContent.replace(' ', '');
<p>    <span> text </span>    </p>