Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

130
Views
How to target & replace the name of a property from a different document in JavaScript?

Im wanting to replace/translate text on a webpage. This is for some online software where I only have access to a custom code section.

Ive managed to translate some words, but my script doesn't have an affect on some others which are populated from a different file called storeSettings.js.

How can I edit my current translation script to translate the words I need in storeSettings.js ?

This is my current translation code to replace the word 'State' with 'County':

window.onload = function() {const replaceOnDocument = (pattern, string, {target = document.body} = {}) => {
  [
    target,
    ...target.querySelectorAll("*:not(script):not(noscript):not(style)")
  ].forEach(({childNodes: [...nodes]}) => nodes
    .filter(({nodeType}) => nodeType === document.TEXT_NODE)
    .forEach((textNode) => textNode.textContent = textNode.textContent.replace(pattern, string)));
};

replaceOnDocument(/State/g, "County");
                        };

And this is the contents of storeSettings.js



 var fillGeneralSettings = function () {
      mergeUnique(settings.general, {
        state: '',
      }, true);

{
          property: 'state',
          field: self.container.find('[name="state"]')
        }

Say I want to replace 'State' with 'County' (cosmetically). Instead of target = document.body in my translation script what should I replace it with to access the content of storeSettings.js?

Thank you! :)

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!