function replaceNbsps(str) { var re = new RegExp(String.fromCharCode(160), "g"); return str.replace(re, " "); } textNode.nodeValue = replaceNbsps(textNode.nodeValue);