createElement (W3C DOM Core method)



var element = document.createElement('h1');

    ('The man who mistook his wife for a hat'));

The example above
creates an <h1> element, and then adds text to

The end result of that operation would be this HTML:

<h1>The man who mistook his wife for a hat</h1>


tagname (DOMString)

The tagName of the element. In
XML this is case-sensitive; in HTML the name can be specified in any
case, but will be converted to the canonical upper-case form of HTML
tag names.


Create an Element node of the specified type.

The created
element can then be added to the document using Node methods such as appendChild or insertBefore.

A created element implements
the Element interface as soon as it’s created, so
attributes can be added to it immediately, without having to append it to
the document first. If the element has default attributes in this document
type, those attributes are automatically created and attached to the

This method creates non-namespaced elements; to create a
namespaced element, use the DOM 2 “createElementNS”createElementNS
method instead.

Return value

The created element node,
with its nodeName set to the specified tag
name, and its localName, prefix and namespaceURI
set to null

Learn HTML5 Online

Get all SitePoint books and courses with a Learnable membership. Start building future-proof websites that are faster, more powerful, and easier to maintain.

No Reader comments

Comments on this post are closed.