All Projects → WebReflection → Qso

WebReflection / Qso

Licence: isc
A MutationObserver like API for CSS selectors.

Programming Languages

javascript
184084 projects - #8 most used programming language

Deprecated: QuerySelectorObserver

Please use qsa-observer instead, as it's been used in various other libraries, hence it's way more battle-tested, and better, than this initial attempt.


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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].