createElementNS (W3C DOM Core method)
| Version | Depr. | Static |
|---|---|---|
| DOM2 | No | No |
| IE7 | FF1.5+ | SA1.3+ | OP9+ |
|---|---|---|---|
| None | Buggy | Buggy | Buggy |
- Returns
Element- Throws
INVALID_CHARACTER_ERR,NAMESPACE_ERR
Example
var element = document.createElementNS
('http://purl.org/dc/elements/1.1/', 'dc:date');
element.appendChild(document.createTextNode('2007-11-22'));
The
example above creates a date element in the Dublin Core
namespace, then adds a text node to it.
The end result of that operation would be this XML:
<dc:date>2007-11-22</dc:date>
Arguments
- namespace (
DOMString) required The
namespaceURIof the element. A value ofnullmeans no namespace.- name (
DOMString) The qualified name of the element.
Description
Create an Element node of the specified qualified
name1 and namespace URI.
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 its 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
element.
Return value
The created element node,
with its tagName and nodeName set to the specified qualified name, its
namespaceURI set to the specified namespace
URI, its prefix extracted from the specified
qualified name (or null if there is no prefix), and its
localName extracted from the qualified name
Compatibility
| Internet Explorer | Firefox | Safari | Opera | |||||||
|---|---|---|---|---|---|---|---|---|---|---|
| 5.5 | 6.0 | 7.0 | 1.5 | 2.0 | 3.0 | 1.3 | 2.0 | 3.0 | 9.0 | 9.5 |
| None | None | None | Buggy | Buggy | Buggy | Buggy | Buggy | Buggy | Buggy | Buggy |
Internet Explorer doesn't implement this method (it returns undefined).
In
Firefox, Opera and
Safari an empty-string namespace is treated the
same as a null namespace (ie. it's taken to mean
no namespace, when it should be treated as a real
namespace URI).
The following notes are about additional data relating to this method when used in practise, rather than being about the method itself; the support table above does not take account of these notes:
In Safari 1.3 and 2 in HTML mode2, a
namespaced element created using this method returns a nodeName in which the localName part is in the canonical uppercase
form, but the prefix part is in the
specified case (resulting in a value such as
dc:DATE)
User-contributed notes
There are no comments yet.
Add a note
To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.