sentinel-js
Version:
JS library that detects new DOM nodes using CSS selectors
23 lines (22 loc) • 616 B
HTML
<html>
<head>
<style id="sentinel-css"></style>
<script src="assets/sentineljs/sentinel.js"></script>
<script>
// use the `sentinel` global object
sentinel.on('.my-div', function(el) {
el.innerHTML = 'The sentinel is always watching.';
});
// add a new div to the DOM
function addDiv() {
var newEl = document.createElement('div');
newEl.className = 'my-div';
document.body.appendChild(newEl);
}
</script>
</head>
<body>
<button onclick="addDiv();">Add another DIV</button>
<div class="my-div"></div>
</body>
</html>