开发者

onchange event for <div> element when I have no control over when it is changed

I have a div element on a page that has other divs added to it when certain events happen. I do not know when these events happen, how they are triggered and how the other divs are added to the main div (its external so I have no idea whats happening all I have access to is the div).

How would I "monitor" for changes to the main div so an event is triggered whenever a new div is added ? I know I can use setInterval (which is what I'm doing now), but I really do not want to use it unless absoluley necessary. I would开发者_Go百科 love to something as simple as form elements do with onchange but I have not found such for divs.

Example if text is not clear:

wesite.com/index.html ( the only thing I have access to)

<html>
<head></head>
<body>
    <div id="theDiv">
    </div>
</body>
</html>

and at times unknown to me divs get added to that div and it eventually looks like :

<html>
<head></head>
<body>
    <div id="theDiv">
        <div class="added"><p>Added Div</p></div>
        <div class="added"><p>Added Div</p></div>
        <div class="added"><p>Added Div</p></div>
        <div class="added"><p>Added Div</p></div>
        <div class="added"><p>Added Div</p></div>
    </div>
</body>
</html>

And lets say I set up the event to trigger an alert, in this example I want to see an alert box every time a new div is added so by the time it looks like this I should have seen 5 alert boxes.

Sorry if this is difficult to follow..


The easiest way is to intercept the calls that are adding the children to the DIVs. Is this not an option?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜