SO-37412469

by David Thomas

HTML

<span id="count">255<span>words</span></span>

JavaScript

//
function getChildTextOf (n) {
  let clone = n.cloneNode(true);
  Array.from( clone.children ).forEach(child => clone.removeChild(child));
  clone.normalize();
  return clone.textContent;
}

console.log(getChildTextOf(document.getElementById('count')));