InDom.getOne(selector, container?)
Shortcut: $1

Queries the DOM using the CSS selector and returns an InDom object that contains the matching DOM element.
Returns null if no matching element is found.

Parameters:
selector {string} - CSS selector string
container {ParentNode | InDom} (optional) - The container element or InDom object to search within. Defaults to document.

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

Examples:
$1('.example>div').setStyle('color', 'blue');
/*
	If .example>div doesn't match any element, $1('.example>div') will return null.
	Attempting to call a method on null will result in a TypeError.
	If you want to avoid this error when the element is not found,
	use the optional chaining operator (?.) e.g.:
*/
$1('.example>div')?.setStyle('color', 'blue');

$1('.example>div').onClick(n => {
	//n here is the InDom object
	n.addClass('clicked').setStyle({ 'color': 'red', 'font-size': '120%' });
});

// Set style to the first 'span', of the first '.example>div'
$1('span', $1('.example>div')).setStyle('color', 'green');

//or:
const div = $1('.example>div');
$1('span', div).setStyle('color', 'green');
Next: get »
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.