When dynamically adding elements to the page, how can we trigger an event by judging the length change of the target element?
巴扎黑2017-07-05 10:50:31
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);
大家讲道理2017-07-05 10:50:31
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
大家讲道理2017-07-05 10:50:31
Can you determine the length of the target element to trigger it after you add the element dynamically?