The tag name of the HTML element to create.
The tag name of the element to create (e.g., 'div', 'span').
Optional
attributes: ElementAttributes<TagName>Optional attributes and styles to set on the element.
style
attribute can be:
csstype
), e.g. { color: "red", fontWeight: "bold" }
"color: red; font-weight: bold;"
Child nodes to append to the created element.
The created HTML element.
// Using a CSS-in-JS object for style (type-safe, with autocomplete)
const el1 = createNode("div", {
textContent: "Hello!",
style: { color: "red", fontWeight: "bold" }
});
// Using a string for style (no type safety or autocomplete)
const el2 = createNode("div", {
textContent: "World!",
style: "color: blue; font-weight: bold;"
});
document.body.append(el1, el2);
Creates a new DOM node of the specified tag name, applies the given attributes, and appends any provided child nodes.