querySelectorAll
A live nodelist using querySelectorAll
.
Click a list entry to remove it. Use the developer tools to add and remove elements. It's not the click/sumbit handlers, it's the live node list that triggers the changes.
The code (excerpts)
var listEl = document.getElementById('query-selector-all-list'),
nodeList = watched(listEl).querySelectorAll('.watched-item');
var updateList = function () {
countEl.textContent = nodeList.length; //update count
nodeList.forEach(function (el, index) {...}); //update every item
};
// Listen to the lists update events
nodeList.on('added', function (addedElements) {
updateList();
});
nodeList.on('removed', function (addedElements) {
updateList();
});