{"id":516,"date":"2022-08-30T15:02:39","date_gmt":"2022-08-30T15:02:39","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/textcontent-is-null-or-not-an-object-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:02:39","modified_gmt":"2022-08-30T15:02:39","slug":"textcontent-is-null-or-not-an-object-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/textcontent-is-null-or-not-an-object-collection-of-common-programming-errors\/","title":{"rendered":"&#39;textContent&#39; is null or not an object-Collection of common programming errors"},"content":{"rendered":"<p>i have a problem with this code this code run great on all browsers exept IE,my IE is 8.0 any solution? i won&#8217;t using jquery sincerely Note: i changed Node.TEXT_NODE to 3 but other error occured:&#8217;textContent&#8217; is null or not an object<\/p>\n<pre><code> \n \n \n \n\n function replaceText(oldText, newText, node){ \n   node = node || document.body; \n\n   var childs = node.childNodes, i = 0;\n\n   while(node = childs[i]){ \n     if (node.nodeType == Node.TEXT_NODE){ \n  node.textContent = node.textContent.replace(oldText, newText); \n} else { \n  replaceText(oldText, newText, node); \n} \n     i++; \n   } \n }\n\n \n \n \n old\n <\/code><\/pre>\n<h1 id=\"myHeader\" onclick=\"replaceText('old','new')\"><code>old Click me! whatever<\/code><\/h1>\n<pre>\n\n \n \n<\/pre>\n<p><code>i found it<\/code><\/p>\n<pre><code><code>   while(i &lt; childs.length){\n   if (rgx.test(document.body.innerHTML)){\n   childs[i][textPropName] =childs[i][textPropName].replace(rgx,'new');\n   }\n   else\n   {\n   replaceText(oldText, newText,document.body.childNodes[i])\n   }\n        i++; \n      } \n    }  \n<\/code><\/code><\/pre>\n<ol>\n<li>\n<p><code>Node.TEXT_NODE<\/code> &amp; <code>textContent<\/code> are not available in IE8.<\/p>\n<p>Use <code>3<\/code> instead of <code>Node.TEXT_NODE<\/code>, and use <code>innerText<\/code> if <code>textContent<\/code> is not available:<\/p>\n<pre><code>var textPropName = node.textContent === undefined ? 'innerText' : 'textContent';\n\nif (node.nodeType == 3) {\n    node[textPropName] = node[textPropName].replace(oldText, newText); \n} else { \n    replaceText(oldText, newText, node); \n}\n<\/code><\/pre>\n<p>You should probably cache that <code>textPropName<\/code> outside your function, so that you don&#8217;t recheck it every single time the function is called (use <code>document.body<\/code> for the test).<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-09 20:02:56. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>i have a problem with this code this code run great on all browsers exept IE,my IE is 8.0 any solution? i won&#8217;t using jquery sincerely Note: i changed Node.TEXT_NODE to 3 but other error occured:&#8217;textContent&#8217; is null or not an object function replaceText(oldText, newText, node){ node = node || document.body; var childs = node.childNodes, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-516","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/516","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=516"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/516\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=516"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=516"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=516"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}