This function translates a variety of input types to an element. You can supply a CSS selector or an HTML markup and get an HTMLElement
in return.
import el from '@web-native-js/play-ui/src/dom/el.js';
el(input);
input
-String|HTMLElement
: A valid CSS selector, HTML markup or an instance ofHTMLElement
. If a selector is provided, only the first-matched element is returned.
HTMLElement
- The resulting DOM element.NULL
- Where input is a CSS selector but matches no element.
In the example below, we are calling this function with a CSS selector.
<body>
<header>
<div>DIV1</div>
</header>
<main>
<div>DIV2</div>
</main>
</body>
let div = el('div');
console.log(div.innerText); // DIV1