.getSelfOrParent(selector)
Available on: InDom

Returns 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:
selector {string} - CSS selector to test against this and ancestors.

Returns: {InDom | null} - InDom object, or null when not found

Throws:
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>`);
Modern DOM Power
for TypeScript, ESM & Plain JS
3.8KB JavaScript library that simplifies DOM manipulation
with a clean, chainable API for events, data, inputs harvesting, and more.
Automatic Cleanup,
Leak-Proof by Design
Events and state are cleared when elements leave the DOM,
even if removal happens outside InDom.
Cleaner Code,
Better Ergonomics
Get the InDom object directly in callbacks.
One element, one instance.
Works With Your Existing Stack
Use InDom on its own or alongside any library or framework,
its architecture ensures a seamless integration.