$(function() {
foo();
function foo() {
var elems = $('.youclass').length();
if (elems) {
console.log('Element IS!');
} else {
foo();
}
}
});
$(function() {
var loaded = false;
var target = document.querySelector('#containerWhereLooking');
var innerElement = 'idNewElements';
var observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
for (var i = mutation.addedNodes.length; i--;) {
if (mutation.addedNodes[i].id == innerElement) {
workerWithNewElement();
loaded = true;
break;
}
}
if (loaded)
observer.disconnect();
});
});
var config = { attributes: true, childList: true, characterData: true }
observer.observe(target, config);
var workWithNewElements = function () {
// work work work ...
};
});