.getSelfOrParent(selector)
Available on: InDomReturns this if its underlying element matches the selector, otherwise the InDom object for its closest ancestor element that matches.
Returns null if nothing is found.Parameters:
Returns null if nothing is found.Parameters:
selector {string} - CSS selector to test against this and ancestors.
Returns: {InDom | null} - InDom object, or null when not foundThrows: Error - If the underlying element has been removed
Examples:// delegate clicks on all links (present or future)
$n(document).onClick((_, e) => {
// _ instead of n because we only need the event object here (for IDEs)
const link = $n(e.target).getSelfOrParent("a");
if (link) {
console.log(`URL:${link.getAttr('href')} clicked`);
}
});
// test link (works even if added later)
$1('body').append(`<a href="https://github.com/constcallid/indom" target="_blank">
InDom - modern JavaScript DOM library</a>`);Next: getNext »