javascript - How to listen for page element additions
大家讲道理
大家讲道理 2017-07-05 10:48:31
0
3
947

When dynamically adding elements to the page, how can we trigger an event by judging the length change of the target element?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(3)
巴扎黑

Listen to this event DOMSubtreeModified.
means that if the child node of the currently monitored element is changed: including deleting a child node, adding a child node, or modifying the content of a child node, this event will be triggered.

var container = document.querySelector(".target")
container.addEventListener('DOMSubtreeModified', function () {
    // do sth
}, false);
大家讲道理

You add a listening event in the dynamically adding element button, and then when the listening event is triggered, judge the length of the target element, and if there is a change, trigger an event

大家讲道理

Can you determine the length of the target element to trigger it after you add the element dynamically?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template