document.addEventListener("DOMContentLoaded", function(event) {
//do work
});
document.addEventListener('DOMContentLoaded', (event) => {
//the event occurred
})
var checkExist = setInterval(function() {
if ($('#my-element').length) {
console.log("Exists!");
clearInterval(checkExist);
}
}, 100); // check every 100ms