createElement (W3C DOM Core method)
var element = document.createElement('h1'); element.appendChild(document.createTextNode ('The man who mistook his wife for a hat'));
The example above
<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>
Element node of the specified type.
A created element implements
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
Internet Explorer in HTML supports a corrupted syntax, that allows a subtree to be created by passing serialized markup to this method, for example:
Safari 1.3 and 2 in XHTML mode or XML1, while not actually supporting this corrupted syntax in full, don't throw an exception either — they return the entire input string as the node name of what appears to be a created element reference; but they haven't actually created an element, and cannot add the data to the page.
1 On XHTML pages served as
There are no comments yet.