Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9203927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:35:04+00:00 2026-06-17T23:35:04+00:00

i use this code to get text of all nodes in body (Browser is

  • 0

i use this code to get text of all nodes in body (Browser is IE8 it works on FF…)

thanks ,i develop a toolbar to change some texts in pages so if you have any other solution will made me happy,if i replace all of body with regex,it disable some futures of sites.for example in facebook if use replace all suggestion future will disable in friend finds section,so i want to change words step by step,it’s a filter for bad words

function replaceText(node)
{
 var textPropName = node.textContent === undefined ? 'innerText' : 'textContent';
 var childs = node.childNodes, i = 0;
 while(i < childs.length)    
 {
 alert(childs[i][textPropName]);
   if (childs[i][textPropName] !=null)
    {
      childs[i][textPropName] =childs[i][textPropName].replace(rgx,'new');
    }
    else
    {
      replaceText(document.body.childNodes[i]);} i++; 
    }
 }
}

it’s work and i can replace all text on a page but if a text be in out of tags same as belove i can’t access to it and replace it
problem: test5 ww tt xx test aren’t in any tag so they don’t replaced
any solution?
sincerely

ww tt ff xx test5 test
<b>
test old old  yyyl  yyy ppp  
  <h2> ppp gfdsgfds gf dg df   yyy old odld old</h2>
</b>
  <h1 id="myHeader" onClick="replaceText(document.body)"> 
     yyy   yyy  yyy  yyy   old Click me! whatever
 </h1>
ppp  ppp ppp bwhoreface 
<b> 
ppp

end solution

function replaceText(node){ 
var textPropName = node.textContent === undefined ? 'innerText' : 'textContent';
   var childs = node.childNodes, i = 0;
var len= node.childNodes.length;
// alert('len='+len);
//var rgx = new RegExp('\\bold\\b', 'gi');
   while(node = childs[i]){
//alert('ee'+node.nodeType);  
if (node.nodeType == 3  ) {
//alert('!!!!!'+node.nodeValue );
//alert('ee'+node.nodeType); 
childs[i].nodeValue = childs[i].nodeValue.replace(rgx, 'newText'); 
} else { 
   replaceText(node); 

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T23:35:05+00:00Added an answer on June 17, 2026 at 11:35 pm

    Here you go, this works in IE too…

    Live Demo

    function replaceText(node)
    {
        var textPropName = node.textContent === undefined ? 'innerText' : 'textContent';
        var childs = node.childNodes, i = 0;
        var rgx = new RegExp('\\bff\\b|\\byyy\\b', 'gi');
    
        while(i < childs.length)    
        {
            if(childs[i].nodeType == 3) {
                alert(childs[i].nodeValue);
    
                childs[i].nodeValue = childs[i].nodeValue.replace(rgx,'new');
            } else {
                alert(childs[i][textPropName]);
    
                if (childs[i][textPropName] !=null)
                {
                    childs[i][textPropName] =childs[i][textPropName].replace(rgx,'new');
                }
                else
                {
                    replaceText(document.body.childNodes[i]);
                } 
            }
    
            i++; 
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using this code to get a drawable and use in a SetCompoundDrawablesWithIntrinsicBounds call:
i use this line of code : [self parseXMLFileAtURL:url]; And i get this error
Why do I get this error message with this code? Use of undeclared identifier
In code: //I know that to get this effect (being able to use it
I use this code : MethodInvoker TileLoadCompleteMethodInvoker = delegate() { CleanStatusLabelTimer.Enabled = true; MemoryTextBox.Text
i use this code in my app. just found is not correct when compare
I use this code to connect to SQL Server 2012, but it does not
I use this code to select password field from the sql server 2012 db,
I use this code , to log $_SERVER['REMOTE_ADDR']; to my small db my issue
I use this code to update data in database table. Can reuse same code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.