DOM : How to detect a new child elements?

前端 未结 3 1078
灰色年华
灰色年华 2020-12-16 18:11

I want to detect the insertion of a new div element only as a direct child of the parent div.

Example:

3条回答
  •  [愿得一人]
    2020-12-16 18:47

    Assume your event handler looks like this:

    function(evt) {
        // whatever
    }
    

    Inside the handler, evt.relatedNode is the element into which the insertion is being performed. You can switch on it and decide to ignore or process the event.

    See it in action.

提交回复
热议问题