Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
118
rated 0 times [  125] [ 7]  / answers: 1 / hits: 68191  / 14 Years ago, thu, february 17, 2011, 12:00:00

How i can make some thing like this?



<div id='myDiv' onload='fnName()'></div>


can't use



window.onload = function () {
fnName();
};

or

$(document).ready(function () {fnName();});


the div element is dynamic. The div content is generated by xml xsl.



Any ideas?


More From » html

 Answers
117

You can use DOM Mutation Observers



It will notify you every time the dom changes, e.g. when a new div is inserted into the target div or page.



I'm copy/pasting the exmple code



// select the target node
var target = document.querySelector('#some-id');

// create an observer instance
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
console.log(mutation.type);
});
});

// configuration of the observer:
var config = { attributes: true, childList: true, characterData: true }

// pass in the target node, as well as the observer options
observer.observe(target, config);

// later, you can stop observing
observer.disconnect();

[#93700] Tuesday, February 15, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
annaliese

Total Points: 86
Total Questions: 97
Total Answers: 107

Location: Dominican Republic
Member since Sun, Sep 4, 2022
2 Years ago
;