{"id":4404,"date":"2026-03-10T10:56:50","date_gmt":"2026-03-10T10:56:50","guid":{"rendered":"https:\/\/ibex.tech\/javascript\/?p=4404"},"modified":"2026-03-10T13:26:42","modified_gmt":"2026-03-10T13:26:42","slug":"replace-string-in-html","status":"publish","type":"post","link":"https:\/\/ibex.tech\/javascript\/manipulating-html\/replace-string-in-html","title":{"rendered":"Replace string in HTML"},"content":{"rendered":"\n<h5 class=\"wp-block-heading\">Target whole page &#8211; NOT RECOMDNDED<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>window.addEventListener('load', function()\n{\n  document.body.innerHTML = document.body.innerHTML.replaceAll(\n    \"REPLACE_THIS_TAG\",\n    \"Replace with this\"\n  );\n});<\/code><\/pre>\n\n\n\n<p><strong>WARNING!!!!!! &#8211; This rewrites the entire &lt;body>, the browser destroys the old DOM nodes and creates new ones. If you&#8217;ve already done things that like attach click handlers they won&#8217;t work!<\/strong><\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Target a section of the page only &#8211; BETTER APPRAOCH<\/h5>\n\n\n\n<p>Better approach, target just a specific section of the page, e.g. within a specific &lt;div&gt; ID:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>window.addEventListener('load', function()\n{\n  const MyContainerId = document.getElementById('MyContainerId');\n  if(MyContainerId)\n  {\n    MyContainerId.innerHTML = MyContainerId.innerHTML.replaceAll(\n      \"REPLACE_THIS_TAG\",\n      \"Replace with this\"\n    );\n  }\n});<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Target whole page &#8211; NOT RECOMDNDED WARNING!!!!!! &#8211; This rewrites the entire &lt;body>, the browser destroys the old DOM nodes and creates new ones. If you&#8217;ve already done things that like attach click handlers they won&#8217;t work! Target a section of the page only &#8211; BETTER APPRAOCH Better approach, target just a specific section of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[74],"tags":[],"class_list":["post-4404","post","type-post","status-publish","format-standard","hentry","category-manipulating-html"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/posts\/4404","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/comments?post=4404"}],"version-history":[{"count":5,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/posts\/4404\/revisions"}],"predecessor-version":[{"id":4410,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/posts\/4404\/revisions\/4410"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/media?parent=4404"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/categories?post=4404"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/tags?post=4404"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}