.getParent(selector?)
Available on: InDom

Returns the InDom object for the closest ancestor (or direct parent if no selector) that matches the selector.
Returns null if nothing is found.

Parameters:
selector {string} (optional) - CSS selector to test against ancestors.

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

Throws:
Error - If the underlying element has been removed

Examples:
const span = $1('.example>div>span');

console.log(span.getParent().getHtml());
// <span>this is a first test</span>

console.log(span.getParent('.example').getHtml());
// <div> <span>this is a first test</span></div>...
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.