Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
With the help of a little recursion, it's straightforward to go through all text nodes and replace their contents: function replaceIn(e) { if (e.nodeType == Node.TEXT_NODE) { e.nodeValue =...
Answer
#3: Post edited
- With the help of a little recursion, it's straightforward to go through all text nodes and replace their contents:
- ```
- function replaceIn(e) {
- if (e.nodeType == Node.TEXT_NODE) {
- e.nodeValue = e.nodeValue.replaceAll("a", "");
- } else {
for (child of e.childNodes) {- replaceIn(child);
- }
- }
- }
- replaceIn(document.body);
- ```
- With the help of a little recursion, it's straightforward to go through all text nodes and replace their contents:
- ```
- function replaceIn(e) {
- if (e.nodeType == Node.TEXT_NODE) {
- e.nodeValue = e.nodeValue.replaceAll("a", "");
- } else {
- for (const child of e.childNodes) {
- replaceIn(child);
- }
- }
- }
- replaceIn(document.body);
- ```
#2: Post edited
With the help of little recursion, it's straightforwards to go through all text nodes and replace their contents:- ```
- function replaceIn(e) {
- if (e.nodeType == Node.TEXT_NODE) {
- e.nodeValue = e.nodeValue.replaceAll("a", "");
- } else {
- for (child of e.childNodes) {
- replaceIn(child);
- }
- }
- }
- replaceIn(document.body);
- ```
- With the help of a little recursion, it's straightforward to go through all text nodes and replace their contents:
- ```
- function replaceIn(e) {
- if (e.nodeType == Node.TEXT_NODE) {
- e.nodeValue = e.nodeValue.replaceAll("a", "");
- } else {
- for (child of e.childNodes) {
- replaceIn(child);
- }
- }
- }
- replaceIn(document.body);
- ```
#1: Initial revision
With the help of little recursion, it's straightforwards to go through all text nodes and replace their contents: ``` function replaceIn(e) { if (e.nodeType == Node.TEXT_NODE) { e.nodeValue = e.nodeValue.replaceAll("a", ""); } else { for (child of e.childNodes) { replaceIn(child); } } } replaceIn(document.body); ```