Document: createElement() method
Baseline
Widely available
*
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
* Some parts of this feature may have varying levels of support.
The createElement() method of the Document interface creates a new HTMLElement that has the specified localName.
If localName isn't recognized, the method creates an HTMLUnknownElement.
Syntax
createElement(localName)
createElement(localName, options)
Parameters
localName-
A string that specifies the type of element to be created. Don't use qualified names (like "html:a") with this method. When called on an HTML document,
createElement()convertslocalNameto lowercase before creating the element. In Firefox, Opera, and Chrome,createElement(null)works likecreateElement("null"). optionsOptional-
An object with the following optional properties (note that only one of
isandcustomElementRegistrymay be set):isOptional-
A string defining the tag name for a custom element previously defined using
customElements.define(). The new element will be given anisattribute whose value is the custom element's tag name. See Web component example for more details. customElementRegistryOptional-
A
CustomElementRegistrythat sets the Scoped custom element registry of a custom element.
Return value
The new Element.
Note: A new HTMLElement is returned if the document is an HTMLDocument, which is the most common case. Otherwise a new Element is returned.