Document.createElementNS()

Questa traduzione è incompleta. Collabora alla traduzione di questo articolo dall’originale in lingua inglese.

Creates an element with the specified namespace URI and qualified name.

Syntax

element = document.createElementNS(namespaceURI, qualifiedName);
  • element is the created element.
  • namespaceURI is a string that specifies the namespace URI to associate with the element. The namespaceURI property of the created element is initialized with the value of namespaceURI. (see section below for "Valid Namespace URI's")
  • qualifiedName is a string that specifies the type of element to be created. The nodeName property of the created element is initialized with the value of qualifiedName

Valid Namespace URI's

  • HTML - Use http://www.w3.org/1999/xhtml
  • SVG - Use http://www.w3.org/2000/svg
  • XBL - Use http://www.mozilla.org/xbl
  • XUL - Use http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul

Example

This creates a new

element in the XHTML namespace and appends it to the vbox element. Although this is not an extremely useful XUL document, it does demonstrate the use of elements from two different namespaces within a single document:

 

 
  
   The script on this page will add dynamic content below:
  
 


Notes

The example given above uses inline script which is not recommended in XHTML documents. This particular example is actually an XUL document with embedded XHTML, however, the recommendation still applies. Inline script does not cause any problems for this short example, however, for any serious work you should learn about Properly Using CSS and JavaScript in XHTML Documents.

To create an element without specifying a namespace URI, use the createElement method.

Specification

See also

Tag del documento e collaboratori

 Hanno collaborato alla realizzazione di questa pagina: fscholz, teoli, Hasilt, Federico
 Ultima modifica di: fscholz,