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;
}