一个MutationObserver,类似于CSS选择器的API
一个MutationObserver,类似于CSS选择器的API
JavaScript CSS相关
共31Star
详细介绍
QuerySelectorObserver
100% inspired by a Daniel's hack, this module brings a friendly MutationObserver like API to observe CSS selectors instead.
const so = new QuerySelectorObserver(records => {
for (const record of records) {
if (record.addedNodes.length) {
record.target.textContent = 'Hello via QSO!';
console.log(record.addedNodes);
} else {
console.log(record.removedNodes);
}
}
});
so.observe('.some-selector');
so.observe('#some-complex > .selector + p.cool');
button.onclick = () => so.disconnect();
Compatible with IE11 and other browsers, feel free to test it live.