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

197
Views
Access variable from MutationObserver callback globally

I have a div that is getting its inner text changed by another element. In my js file I have the following, which on DOM ready state, starting monitoring the target for mutations. If I put, for example, console.log() of any of the vars inside changeToVar function, it behaves as expected and accesses the variables. What I want though is to be able to access the MON_DATA and CONT_DATA outside of the changeToVar function.

document.addEventListener("DOMContentLoaded", function (event) {
  var target = document.getElementById("recidRecord");
  var observer = new MutationObserver(function (mutations) {
    changeToVar(target.innerText);
  });

  observer.observe(target, {
    attributes: true,
    childList: true,
    characterData: true,
  });
});

function changeToVar(target) {
  window.data = target;
  var CONST_DATA = CONST_DETAILS[window.data];
  window.MON_DATA = CONST_DATA.monitored_props;
  window.CONT_DATA = CONST_DATA.contingencies;
}
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!