InDom.getOne(selector, container?)
Shortcut: $1Queries 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:
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 foundExamples:$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 »