Methods
(static) createElement(config) → {HTMLElement}
- Source:
Example
import { createElement } from '@untemps/utils/dom/createElement'
createElement({
tag: 'p',
attributes: { id: 'foo', style: 'font-weight: bold' },
textContent: 'Foo',
parentSelector: 'body'
}) // <p id="foo" style="font-weight: bold">Foo</p>
Parameters:
Name |
Type |
Description |
config |
object
|
The configuration object for the new DOM element.
Properties
Name |
Type |
Attributes |
Default |
Description |
tag |
string
|
<optional>
|
'div'
|
The tag name of the new DOM element to create. All valid HTML tags are accepted (See https://www.w3schools.com/TAGS/default.asp). |
attributes |
object.<string, *>
|
<optional>
|
{}
|
The attributes to pass to the new DOM element. All valid attributes for the specified HTML tag are accepted. |
content |
HTMLElement
|
<optional>
|
null
|
A DOM element to append as child of the new DOM element. This property has precedence over textContent . |
textContent |
string
|
<optional>
|
null
|
A text to append as child of the new DOM element. |
parent |
HTMLElement
|
<optional>
|
null
|
A DOM element to which append the new DOM element. This property has precedence over parentSelector . |
parentSelector |
string
|
<optional>
|
null
|
A selector of a DOM element to which append the new DOM element. |
boundingClientRect |
Object
|
<optional>
|
null
|
The values returned by the getBoundingClientRect function. Useful in jsdom environment. |
|
Returns:
-
Type
-
HTMLElement