.onRemove(fn)
Available on: InDom, InDomArrayRegisters a callback function that runs after the object's internal state (listeners, data) has been cleaned up, and just before its element is removed from the DOM.Parameters:
fn {(n: InDom) => void} - The callback function
Returns: {Function | Function[]} - The internal handler(s) – pass to .off('onRemove', …) to unregisterThrows: TypeError - If fn is not a function
Error - If the underlying element(s) has been removed
Examples:const example = $1('.example');
// callback fires no matter how the element is removed
example.onRemove(() => {
console.log('removed:', example);
alert('press OK → element disappears');
});
// Through InDom remove method on the object
example.remove();
// Through InDom setHtml on body
$1('body').setHtml('empty');
// Through native DOM removal
document.querySelector('.example').remove();
// Through native innerHTML on its parent
document.querySelector('.example').parentElement.innerHTML = 'empty';Next: off »