Browser/User Agent Support
| IE | Mozilla | Netscape | Opera | Safari | Netscapte | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | no |
|---|
Constructors
| Constructor | IE | Mozilla | Netscape | Opera | Safari | Netscapte |
|---|---|---|---|---|---|---|
Creates a new instance of a Document object. | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | no |
Properties
| Property | IE | Mozilla | Netscape | Opera | Safari | Netscapte |
|---|---|---|---|---|---|---|
Reference to the Element that currently has focus. | 4.0+ | no | no | no | no | no |
Specifies the color of active links. | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | no |
Array of all of the Anchor objects in a document. | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | no |
Array of all of the Applet objects in a document. | 4.0+ | 1.0+ | 3.0+ | 7.0+ | 1.0+ | no |
Background color of a document. | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | no |
Reference to the body or frameset element. | 4.0+ | 1.0+ | 6.0+ | 7.0+ | 1.0+ | no |
Character set of the document. | 4.0+ | no | no | no | no | no |
Character set of the document. | no | 1.0+ | 6.0+ | no | 1.0+ | no |
Array of style properties for CSS classes. | no | no | 4.0+ | no | no | no |
Indicates whether the document has standards-compliant mode turned on. | 6.0+ | 1.75+ | 7.0+ | no | no | no |
Value of the cookie that the browser has set for the document. | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | no |
Default character set for the document. | 4.0+ | no | no | no | no | no |
Specifies that design mode for an HTML document is "on" or "off." | 5.0+ | 1.4+ | 7.0+ | no | no | no |
Text direction of the content in the document. | 5.0+ | 1.0+ | 6.0+ | no | no | no |
Document Data Type (DTD) associated with this document. | 6.0+ | 1.0+ | 6.0+ | 7.0+ | no | no |
Root element in a document. | 5.0+ | 1.0+ | 6.0+ | 7.0+ | 1.0+ | no |
Internet domain of the document. | 4.0+ | 1.0+ | 3.0+ | 7.0+ | 1.0+ | no |
Array of all embedded objects in the document. | 4.0+ | 1.0+ | 3.0+ | 7.0+ | 1.0+ | no |
Indicates whether a client-side object may have instance properties added to it. | 4.0+ | no | no | no | no | no |
Font color of the document text. | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | no |
Date that the document was created. | 4.0+ | no | no | no | no | no |
Date that the document was last modified. | 4.0+ | no | no | no | no | no |
File size (in bytes) of the document. | 4.0+ | no | no | no | no | no |
Array of all of the Forms in the document. | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | no |
Array of all of the Frames in the document. | 4.0+ | no | no | no | no | no |
Height of the entire HTML document (in pixels). | no | 1.0+ | 4.0+ | 7.0+ | 1.0+ | no |
Array of style properties in the document set by the Id attribute. | no | no | 4.0+ | no | no | no |
Array of Image objects in the document. | 4.0+ | 1.0+ | 3.0+ | 7.0+ | 1.0+ | no |
Object that specifies whether or not and at what level the browser supports the specified feature. | 6.0+ | 1.0+ | 6.0+ | 7.0+ | 1.0+ | no |
Date that the document was last modified. | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | no |
Array of all of the Layer elements in the document. | no | no | 4.0+ | no | no | no |
Color of the unvisited links in the document. | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | no |
Array of all of the links in the document. | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | no |
Complete URL of the document. | 3.0+ | no | 3-4 | no | no | no |
The media that the document is intended for. | 5.5+ | no | no | no | no | no |
Information about the document MIME type. | 5.0+ | no | no | no | no | no |
Array of the XML Namespaces for a document. | 5.5+ | no | no | no | no | no |
Fires when the element becomes active. | 4.0+ | no | no | no | no | no |
Fires immediately before the selection is cut to the clipboard. | 4.0+ | no | no | no | 1.0+ | no |
Fires immediately before the element stops being the active element. | 4.0+ | no | no | no | no | no |
Fires immediately before the element receives focus prior to being edited. | 4.0+ | no | no | no | no | no |
Fires immediately before the selection is pasted from the clipboard to the element. | 4.0+ | no | no | no | 1.0+ | no |
Fires when the element is clicked. | 2.0+ | 1.0+ | 1.0+ | 4.0+ | 1.0+ | no |
Fires when the element is right-clicked and the context menu opens. | 4.0+ | no | no | no | 1.0+ | no |
Fires immediately before the element is selected. | 4.0+ | no | no | no | no | no |
Fires when the element is cut to the clipboard. | 4.0+ | no | no | no | 1.0+ | no |
Fires when the element is double-clicked. | 2.0+ | 1.0+ | 1.0+ | 4.0+ | 1.0+ | no |
Fires when the element is dragged. | 4.0+ | no | no | no | 1.0+ | no |
Fires when the element is released from being dragged. | 4.0+ | no | no | no | 1.0+ | no |
Fires when the element has another object dragged onto it that can be dropped on the element. | 4.0+ | no | no | no | 1.0+ | no |
Fires when an element has an object dragged out of it that could be dropped onto the element. | 4.0+ | no | no | no | 1.0+ | no |
Fires when an element has an object dragged over it that could be dropped onto the element. | 4.0+ | no | no | no | 1.0+ | no |
Fires immediately before an element is dragged. | 4.0+ | no | no | no | 1.0+ | no |
Fires when an object is dropped onto the element. | 4.0+ | no | no | no | 1.0+ | no |
Fires when a user presses the F1 key to activate help. | 4.0+ | no | no | no | no | no |
Fires when a user presses down on a key while the element has focus. | 2.0+ | 1.0+ | 1.0+ | 4.0+ | 1.0+ | no |
Fires when a user presses a key or holds down the key while the element has focus. | 2.0+ | 1.0+ | 1.0+ | 4.0+ | 1.0+ | no |
Fires when a user releases a key while the element has focus. | 2.0+ | 1.0+ | 1.0+ | 4.0+ | 1.0+ | no |
Fires when a user clicks down on the mouse button while the element has focus. | 2.0+ | 1.0+ | 1.0+ | 4.0+ | 1.0+ | no |
Fires when the mouse moves while the pointer over the element. | 2.0+ | 1.0+ | 1.0+ | 4.0+ | 1.0+ | no |
Fires when the mouse pointer moves off of the element. | 2.0+ | 1.0+ | 1.0+ | 4.0+ | 1.0+ | no |
Fires when the mouse pointer moves over the element. | 2.0+ | 1.0+ | 1.0+ | 4.0+ | 1.0+ | no |
Fires when the user releases the mouse button while the element has focus. | 2.0+ | 1.0+ | 1.0+ | 4.0+ | 1.0+ | no |
Fires when the clipboard contents are pasted onto the element. | 4.0+ | no | no | no | 1.0+ | no |
Fires when one of the properties of the element changes. | 4.0+ | no | no | no | no | no |
Fires when the ready state of the element changes. | 4.0+ | no | no | no | no | no |
Fires immediately before an element is about to be resized. | 4.0+ | no | no | no | 1.0+ | no |
Fires when the element is finished being resized. | 4.0+ | no | no | no | no | no |
Fires immediately before a user resizes the element. | 4.0+ | no | no | no | no | no |
Fires when the selected state of the document changes. | 5.5+ | no | no | no | no | no |
Fires when a user clicks the Stop button on the browser. | 5.5+ | no | no | no | no | no |
Reference to the parent Window of the document. | 4.0+ | no | no | 8.0+ | no | no |
Array of plugins installed in the browser. | 2.0+ | 1.0+ | 1.0+ | 7.0+ | 1.0+ | no |
Full name of the protocol (not "http") used to retrieve the document. | 4.0+ | no | no | no | no | no |
URL of the referring document. | 2.0+ | 1.0+ | 1.0+ | 7.0+ | 1.0+ | no |
Array of all of the Scripts in the document. | 4.0+ | no | no | no | no | no |
Information about the security certificate for the document. | 5.5+ | no | no | no | no | no |
Object representing any currently selected text. | 4.0+ | no | no | no | no | no |
Array of all of the styleSheets in the document. | 4.0+ | 1.0+ | 6.0+ | 7.0+ | 1.2+ | no |
| ||||||
Array of style properties for certain HTML tags. | no | no | 4.0+ | no | no | no |
Title of the document. | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | no |
URL of the document. | 4.0+ | 1.0+ | 2.0+ | no | no | no |
URL-unencoded version of the URL. | 5.5+ | no | no | no | no | no |
Color of visited links. | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | no |
Width of the HTML document (in pixels). | no | 1.0+ | 4.0+ | 7.0+ | 1.0+ | no |
Reference to the top-level node of the XML DOM used by the document. | 5.0+ | no | no | no | no | no |
Reference to the XSL document for the document. | 5.0+ | no | no | no | no | no |
Methods
| Method | IE | Mozilla | Netscape | Opera | Safari | Netscapte |
|---|---|---|---|---|---|---|
Sets an document to capture the events specified by eventMask. | no | no | 4.0+ | no | no | no |
Clears the content from the document. | 3.0+ | 1.0+ | 2.0+ | no | 1.0+ | no |
Stops the output stream to the document. | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | no |
Sets a concept to select tags to style. | no | no | 4.0 | no | no | no |
Creates a new Attr node | 6.0+ | 1.0+ | 6.0+ | 7.0+ | 1.0+ | no |
| ||||||
Creates a new Attr using a namespace. | 6.0+ | 1.0+ | 6.0+ | 7.0+ | 1.0+ | no |
Creates a new CDATASection node | no | 1.0+ | no | no | no | no |
Creates a new Comment node | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | no |
Creates an empty DocumentFragment object | 6.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | no |
Creates a new Element node of the type specified by tagName (e.g. li element.) | 5.0+ | 1.75+ | 6.0+ | 8.0+ | 1.3+ | no |
| ||||||
Creates a new Element node with a namespace. | no | 1.0+ | 6.0+ | 9.0+ | 1.3+ | no |
Creates a new EntityReference object | no | 1.0+ | no | no | no | no |
Creates a new Event object to be used by the fireEvent method. | 5.0+ | no | no | no | no | no |
Creates a new ProcessingInstruction node with the specified target and data strings. | no | 1.0+ | no | no | no | no |
Creates a new StyleSheet object. | 4.0+ | no | no | no | no | no |
Creates a new Text node. | 5.0+ | 1.75+ | no | 8.0+ | 1.3+ | no |
Returns the element found at the specified x, y location in the document. | 4.0+ | no | no | no | no | no |
Executes the specified command on the document. | 4.0+ | 1.4+ | 7.1+ | no | no | no |
Gives focus to the document and fires the onfocus event handler. | 5.5+ | no | no | no | no | no |
Returns the Element node that matches the given ID. | 5.0+ | 1.0+ | 6.0+ | 7.0+ | 1.0+ | no |
| ||||||
Returns an array of Element nodes with the specified tag name. | 5.0+ | 1.0+ | 6.0+ | 7.0+ | 1.0+ | no |
| ||||||
Returns the Element nodes with the specified element name and namespace. | no | 1.0+ | no | no | no | no |
Returns the text currently selected by the user. | no | no | 4.0+ | no | no | no |
Imports a node from a different document. | no | 1.0+ | no | no | no | no |
Returns true if the specified feature and version are supported. | no | 1.0+ | 6.0+ | no | no | no |
Opens the document for writing. | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | no |
Returns true if the specified command is enabled. | 4.0+ | 1.4+ | 7.1+ | no | no | no |
Returns true if the specified command is in an indeterminate state. | 4.0+ | 1.4+ | 7.1+ | no | no | no |
Returns true if the specified command has been executed on the object. | 4.0+ | 1.4+ | 7.1+ | no | no | no |
Returns true if the specified command is supported. | 4.0+ | 1.4+ | 7.1+ | no | no | no |
Returns the value of the specified command for the document. Returns false if the command is not supported. | 4.0+ | 1.4+ | 7.1+ | no | no | no |
Reevaluates all dynamic properties in the document. | 5.0+ | no | no | no | no | no |
Sets the document to stop capturing the specified type of events. | no | no | 4.0+ | no | no | no |
Routes the specified event to the next event handler. | no | no | 4.0+ | no | no | no |
Gives information about the currently selected objects in the document. | 4.0+ | no | no | no | no | no |
Writes the specified string of text to the end of the document. | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | no |
Writes the specified string of text to the end of the document and adds a newline character at the end of the text. | 3.0+ | 1.0+ | 2.0+ | 7.0+ | 1.0+ | no |
Remarks
This object interface represents an entire HTML or XML document. For most applications, this
will be the effective root of an object tree, since elements, text nodes, and other XML-based
source content cannot exist outside of a Document object. This object contains all the
factory methods necessary to create additional objects along these lines. All nodes created with this document
have their
Within Mozilla (either with XUL running in a chrome environment, or HTML working within a browser)
the Document object representing the current document is usually set automatically
to the global
References
Availability
HTML DOM Level 1 | HTML DOM Level 2 | W3C
Constructor Detail
Property Detail
Element activeElement - read only
Reference to the Element that currently has focus.
String alinkColor
Specifies the color of active links.
- Remarks
- Use the
alinkproperty of the tag to initially set the color of active links. To set this property, use the color properties of HTMLBodyElement to set the color in the tag. - See Also
- Availability
HTML DOM Level 0
Array anchors - read only
Array of all of the Anchor objects in a document.
- Remarks
- Because the Anchors array is read-only, modify the array by adding and deleting anchor elements. Do not confuse Anchors with hypertext links.
- Availability
HTML DOM Level 1
Array applets - read only
Array of all of the Applet objects in a document.
- Remarks
- Because the Applets array is read-only, modify the array by adding and deleting applet elements.
- Availability
HTML DOM Level 1
String bgColor
Background color of a document.
- Remarks
- Use the
bgColorproperty of thetag to set the document background color. To set this bgColor, use the color properties of HTMLBodyElement to set the color at any time. - See Also
- Availability
HTML DOM Level 1
Element body
Reference to the body or frameset element.
-
For examples, see the quirksmode test page:
- Remarks
-
For additional compatibility information, see the quirksmode page:
- Availability
HTML DOM Level 1
String charset - read only
Character set of the document.
String characterSet - read only
Character set of the document.
Array classes - read only
Array of style properties for CSS classes.
Boolean compatMode
Indicates whether the document has standards-compliant mode turned on.
-
For examples, see the quirksmode test page:
String cookie
Value of the cookie that the browser has set for the document.
- Availability
HTML DOM Level 1
String defaultCharset - read only
Default character set for the document.
String designMode
Specifies that design mode for an HTML document is "on" or "off."
- Remarks
- If design mode is on, a user can double-click the document to edit its HTML.
String dir
Text direction of the content in the document.
-
For examples, see the quirksmode test page:
- Availability
HTML DOM Level 0
DocumentType doctype - read only
Document Data Type (DTD) associated with this document.
- Remarks
-
Every document can contain a
Document Type Declaration(DTD) that defines document structure and entity references for the document. Thedoctypeproperty represents the state of this document's DTD, which is either aDocumentTypeobject, ornull, if no DTD is specified. - Availability
HTML DOM Level 2 | W3C
Element documentElement - read only
Root element in a document.
-
For examples, see the quirksmode test page:
- Remarks
-
documentElementis a convenience property for accessing the contents of a document.Without the
documentElementproperty, you would have to writedoc.childNodes.item(0)ordoc.childNodes[0]to access the contents of a document, instead of just typingdoc.documentElement. - Availability
HTML DOM Level 2 | W3C
String domain
Internet domain of the document.
- Availability
HTML DOM Level 1
Array embeds - read only
Array of all embedded objects in the document.
- Remarks
embedsis a read-only property. You can add, delete, or modify the individual objects in the array, but you cannot modify the array itself.- See Also
Boolean expando
Indicates whether a client-side object may have instance properties added to it.
- Remarks
- Use
expandoto help catch typos and case-sensitivity issues in your JavaScript.
String fgColor
Font color of the document text.
- Remarks
- Use the
fgColorproperty of the <body> tag to initially set the color of the document text. To set this property, use the color properties of HTMLBodyElement to set the color in the <head> tag. - See Also
- Availability
HTML DOM Level 0
String fileCreatedDate - read only
Date that the document was created.
String fileModifiedDate - read only
Date that the document was last modified.
Number fileSize - read only
File size (in bytes) of the document.
Array forms - read only
Array of all of the Forms in the document.
- Remarks
- Although the
Formsarray is read-only, you can modify the individualFormelements. - Availability
HTML DOM Level 1
Array frames - read only
Array of all of the Frames in the document.
- Remarks
- Although the
Framesarray is read-only, you can modify the individualFrameelements.
Number height - read only
Height of the entire HTML document (in pixels).
Array ids - read only
Array of style properties in the document set by the Id attribute.
- Remarks
- Although the
Idsarray is read-only, you can modify the individualIdelements.
Array images - read only
Array of Image objects in the document.
- Remarks
- Although the
Imagesarray is read-only, you can modify the individualImageelements. - Availability
HTML DOM Level 1
Object implementation - read only
Object that specifies whether or not and at what level the browser supports the specified feature.
- Availability
HTML DOM Level 2 | W3C
String lastModified - read only
Date that the document was last modified.
- Availability
HTML DOM Level 0
Array layers - read only
Array of all of the Layer elements in the document.
- Remarks
- Includes
divs positioned by CSS.
String linkColor
Color of the unvisited links in the document.
- See Also
- Availability
HTML DOM Level 0
Array links - read only
Array of all of the links in the document.
- Remarks
- Although the
Linkarray is read-only, you can modify the individualLinkelements. - Availability
HTML DOM Level 1
Object location
Complete URL of the document.
- Remarks
- Deprecated for Window.location.
- See Also
String media
The media that the document is intended for.
String mimeType - read only
Information about the document MIME type.
Array namespaces - read only
Array of the XML Namespaces for a document.
Function onactivate - read only
Fires when the element becomes active.
Function onbeforecut - read only
Fires immediately before the selection is cut to the clipboard.
Function onbeforedeactivate - read only
Fires immediately before the element stops being the active element.
Function onbeforeeditfocus - read only
Fires immediately before the element receives focus prior to being edited.
Function onbeforepaste - read only
Fires immediately before the selection is pasted from the clipboard to the element.
Function onclick - read only
Fires when the element is clicked.
Function oncontextmenu - read only
Fires when the element is right-clicked and the context menu opens.
Function oncontrolselect - read only
Fires immediately before the element is selected.
Function oncut - read only
Fires when the element is cut to the clipboard.
Function ondblclick - read only
Fires when the element is double-clicked.
Function ondrag - read only
Fires when the element is dragged.
Function ondragend - read only
Fires when the element is released from being dragged.
Function ondragenter - read only
Fires when the element has another object dragged onto it that can be dropped on the element.
Function ondragleave - read only
Fires when an element has an object dragged out of it that could be dropped onto the element.
Function ondragover - read only
Fires when an element has an object dragged over it that could be dropped onto the element.
Function ondragstart - read only
Fires immediately before an element is dragged.
Function ondrop - read only
Fires when an object is dropped onto the element.
Function onhelp - read only
Fires when a user presses the F1 key to activate help.
Function onkeydown - read only
Fires when a user presses down on a key while the element has focus.
Function onkeypress - read only
Fires when a user presses a key or holds down the key while the element has focus.
Function onkeyup - read only
Fires when a user releases a key while the element has focus.
Function onmousedown - read only
Fires when a user clicks down on the mouse button while the element has focus.
Function onmousemove - read only
Fires when the mouse moves while the pointer over the element.
Function onmouseout - read only
Fires when the mouse pointer moves off of the element.
Function onmouseover - read only
Fires when the mouse pointer moves over the element.
Function onmouseup - read only
Fires when the user releases the mouse button while the element has focus.
Function onpaste - read only
Fires when the clipboard contents are pasted onto the element.
Function onpropertychange - read only
Fires when one of the properties of the element changes.
Function onreadystatechange - read only
Fires when the ready state of the element changes.
Function onresize - read only
Fires immediately before an element is about to be resized.
Function onresizeend - read only
Fires when the element is finished being resized.
Function onresizestart - read only
Fires immediately before a user resizes the element.
Function onselectionchange - read only
Fires when the selected state of the document changes.
Function onstop - read only
Fires when a user clicks the Stop button on the browser.
Object parentWindow - read only
Reference to the parent Window of the document.
-
For examples, see the quirksmode test page:
- See Also
Array plugins - read only
Array of plugins installed in the browser.
- Remarks
- Synonym for the embeds[] array.
- See Also
String protocol
Full name of the protocol (not "http") used to retrieve the document.
- Remarks
- IE only. Supported in IE4+.
String referrer - read only
URL of the referring document.
- Remarks
-
If a user reaches the current document by clicking a link in another document, the
referrerproperty holds the URL for the document with the link. If the user typed the URL into the address bar, thereferrerproperty is an empty string. - Availability
HTML DOM Level 1
Array scripts - read only
Array of all of the Scripts in the document.
String security - read only
Information about the security certificate for the document.
Object selection - read only
Object representing any currently selected text.
Array styleSheets - read only
Array of all of the styleSheets in the document.
-
For examples, see the quirksmode test page:
- Availability
HTML DOM Level 2
Array tags - read only
Array of style properties for certain HTML tags.
String title - read only
Title of the document.
-
For examples, see the quirksmode test page:
- Remarks
- The title is the text that appears between the
titletags of an HTML document. - Availability
HTML DOM Level 1
String URL
URL of the document.
- Remarks
- See Also
String URLUnencoded - read only
URL-unencoded version of the URL.
- See Also
String vlinkColor
Color of visited links.
- Remarks
- Use the
vlinkproperty of the tag to initially set the color of visted links. To set this property, use the color properties of HTMLBodyElement to set the color in the tag. - See Also
- Availability
HTML DOM Level 0
Number width - read only
Width of the HTML document (in pixels).
Object XMLDocument
Reference to the top-level node of the XML DOM used by the document.
Object XSLDocument - read only
Reference to the XSL document for the document.
Method Detail
captureEvents(Number eventMask) : void
Sets an document to capture the events specified by eventMask.
| Number | eventMask | Bitmask containing the events to capture. |
- Remarks
- Supported in Mozilla and NS4+.
- See Also
clear() : void
Clears the content from the document.
close() : Object
Stops the output stream to the document.
- Availability
HTML DOM Level 0
contextual(String context) : void
Sets a concept to select tags to style.
| String | context | Name of the context to be used. (one-or-more) |
createAttribute(String name) : static Attr
Creates a new Attr node
| String | name | Name of the attribute to create. |
-
Using createAttribute
var ele = document.createElement('a'); var href = document.createAttribute('href'); href.value = 'http://mozref.com'; ele.setAttributeNode(href); ele.appendChild(document.createTextNode('Mozilla AOM Reference'));For more examples, see the quirksmode test page:
- Remarks
-
Although
Attributeobjects can only be bound toElementobjects, they can be created by aDocumentobject and later be bound to an element usingsetAttributeNode.While an
Attrnode may contain several different properties, this method only populates thenodeNameproperty and sets the attributevalueset tonull. ThelocalName,prefix, andnamespaceURIproperties are all set tonull. To set those values, use thecreateAttributeNSmethod. - Throws
- Raises an INVALID_CHARACTER_ERR error if the specified qualified name contains an illegal character.
- See Also
- Availability
HTML DOM Level 2 | W3C
createAttributeNS(String namespaceURI, String qualifiedName) : static Attr
Creates a new Attr using a namespace.
| String | namespaceURI | The namespace of the new attribute. |
| String | qualifiedName | The qualified name (e.g. rdf:about) of the attribute to create. |
- Remarks
-
Similar to
createAttribute,createAttributeNScreates a newAttrwithin the current document, butcreateAttributeNSuses namespaces and can populate many of the attribute properties using the specifiednamespaceURI,qualifiedNameobjects.This method will do its best to populate as many propertys as it can, to the best of its ability. For more information about these properties, please see their respective objects.
- Throws
- Raises an INVALID_CHARACTER_ERR error if the specified qualified name contains an illegal character.
- Raises NAMESPACE_ERR error if the qualifiedName is malformed, if the qualifiedName has a prefix and the namespaceURI is null, if the qualifiedName has a prefix that is "xml" and the namespaceURI is different from "http://www.w3.org/XML/1998/namespace", or if the qualifiedName is "xmlns" and the namespaceURI is different from "http://www.w3.org/2000/xmlns/".
- See Also
- Availability
HTML DOM Level 2 | W3C
createCDATASection(Object data) : CDATASection
Creates a new CDATASection node
| Object | data | The text to wrap up into a new CDATASection object. |
-
Using createCDATASection
var cdata = document.createCDATASection( 'this &p invalid markup &exists in this CDATA & section' ); var obj = document.getElementById('header'); obj.appendChild(cdata); - Remarks
-
Creates a new
CDATASectionobject within the current document, representing a region of uninterpreted content. Any text within this object, with the exception of the string "]]>", will not be encoded or otherwise interpreted by the DOM engine. - Throws
- Raises a NOT_SUPPORTED_ERR error if the current document is an HTML document.
- Availability
HTML DOM Level 2 | W3C
createComment(String data) : Comment
Creates a new Comment node
| String | data | The text to include in the comment. |
-
Using createComment
var comment = document.createComment('this text will not appear in HTML'); var obj = document.getElementById('header'); obj.appendChild(comment); - Remarks
-
Creates a new
Commentobject that can be used for adding a region of commented text for inclusion into the current document. Any text within this object, with the exception of the string "-->" will be protected within the document. - Availability
HTML DOM Level 2 | W3C
createDocumentFragment() : DocumentFragment
Creates an empty DocumentFragment object
-
For examples, see the quirksmode test page:
- Availability
HTML DOM Level 2 | W3C
createElement(String tagName) : static HTMLElement
Creates a new Element node of the type specified by tagName (e.g. li element.)
| String | tagName | The tag name of the element to be created. |
-
Using createElement
var newList = document.createElement('ol'); newList.setAttribute('class', 'features'); document.getElementById('sidebar').appendChild(newList);For additional examples, see the quirksmode test page:
- Remarks
-
Use
createElementto create a newElementto later include in theDocument. Returns a newElement, complete with any default attributes that are defined by the theDocumentTypeobject, which represents theDTDfor the document.Because
createElementdoes not supportnamespaces, thelocalName,prefix, andnamespaceURIproperties are all set tonull. To create elements withnamespaces(e.g.XULelements), usecreateElementNS. - Throws
- Raises an INVALID_CHARACTER_ERR error if the specified name contains an illegal character.
- Availability
HTML DOM Level 2 | W3C
createElementNS(String namespaceURI, String qualifiedName) : static HTMLElement
Creates a new Element node with a namespace.
| String | namespaceURI | Namespace of the new element. |
| String | qualifiedName | Qualified name (e.g. myns:element) of the element to create. |
-
Using createElementNS
var newButton = document.createElement( 'http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul', 'xul:button' ); - Remarks
-
Use
createElementNSto create a new element with anamespacein a document.By simply supplying both the
namespace URIand thequalified nameof the element, the following values are extracted to create a fully-formed namespace-aware element:Element properties set by createElementNSProperty left Value left localNameThe local nameof this tag name, extracted fromqualifiedNamenamespaceURInamespaceURInodeNamequalifiedNameprefix The namespace prefixextracted fromqualifiedName, ornullif this element does not define a prefixtagNamequalifiedName - Throws
- Raises an INVALID_CHARACTER_ERR error if the specified qualified name contains an illegal character.
- Raises a NAMESPACE_ERR error if the qualifiedName is malformed, if the qualifiedName has a prefix and the namespaceURI is null, or if the qualifiedName has a prefix that is "xml" and the namespaceURI is different from "http://www.w3.org/XML/1998/namespace"
- Availability
HTML DOM Level 2 | W3C
createEntityReference(String name) : static EntityReference
Creates a new EntityReference object
| String | name | Name of the new entity reference. |
- Remarks
-
Creates a new
EntityReferenceobject with the specifiedname.If the requested entity name is already known to the current document, the returned
EntityReferenceobject's children are set to the same as the correspondingEntity. This makes creatingentity referencesin your document much easier, since it eliminates a step. - Throws
- Raises an INVALID_CHARACTER_ERR error if the specified name contains illegal characers. Raises a NOT_SUPPORTED_ERR error if the current document is an HTML document.
- Availability
HTML DOM Level 2 | W3C
createEventObject(String eventObj) : static Event
Creates a new Event object to be used by the fireEvent method.
| String | eventObj | Event to clone properties for, if copying from an existing Event. (zero-or-more) |
- See Also
Event | MouseEvent | MutationEvent | UIEvent
- Availability
HTML DOM Level 2
createProcessingInstruction(String target, String data) : ProcessingInstruction
Creates a new ProcessingInstruction node with the specified target and data strings.
| String | target | Name, or "target", of the processing instruction to create. |
| String | data | Data to store in the processing instruction. |
-
Using createProcessingInstruction
document.createProcessingInstruction( 'xml-stylesheet', 'href="docbook.xsl" type="text/xsl"' ); - Remarks
-
Creates a new
ProcessingInstructionat the beginning of the current document using the specifiedtargetanddatavalues. - Throws
- Raises an INVALID_CHARACTER_ERR error if the specified target contains illegal characers.
- Raises a NOT_SUPPORTED_ERR error if the current document is an HTML document.
- See Also
- Availability
HTML DOM Level 2 | W3C
createStyleSheet([String url,] [Number index]) : static styleSheet
Creates a new StyleSheet object.
| String | url | URL to create the styleSheet object from. Default is to create an empty styleSheet. (optional) |
| Number | index | Index in the document to add the styleSheet. Default is to add the styleSheet to the end of the document. (optional) |
-
For examples, see the quirksmode test page:
- Remarks
- IE only. Supported in IE4+.
- See Also
createTextNode(String data) : static String
Creates a new Text node.
| String | data | Text to include in the Text node. |
-
Using createTextNode
var newEle = document.createElement('b'); var newText = document.createTextNode('this text is bold'); newEle.appendChild(newText);For additional examples, see the quirksmode test page:
- Remarks
-
Creates a new
Textnode for insertion into the DOM tree.Textnodes represent text within a document as a child of another element, such as the document content that is displayed to the user. - Availability
HTML DOM Level 2 | W3C
elementFromPoint(Number x, Number y) : HTMLElement
Returns the element found at the specified x, y location in the document.
| Number | x | Horizontal (x) position (in pixels) of the element to return. |
| Number | y | Vertical (x) position (in pixels) of the element to return. |
- Remarks
- IE only. Supported in IE4+.
execCommand(String command, [Boolean UI,] [Object value]) : static Boolean
Executes the specified command on the document.
| String | command | Command to execute. |
| Boolean | UI | Specify true to display a user interface. Default is false. (optional) |
| Object | value | Value to assign, depending on the command. (optional) |
focus() : static Object
Gives focus to the document and fires the onfocus event handler.
- Remarks
- IE only. Supported in IE5.5+.
getElementById(String id) : static HTMLElement
Returns the Element node that matches the given ID.
| String | id | Id of the element to get. |
-
Using getElementById
var emailproperty = document.getElementById("email-textbox"); var emailAddress = emailproperty.getAttribute("value");For additional examples, see the quirksmode test page:
- Remarks
-
Use
getElementByIdto avoid traversing multiple child nodes to retrieve a value.Use a naming convention to assign unique Element id's so that you can easily retrieve information from the object model of your document without having add the id's later.
The
DOM Level 2 Corespecification does not define specific behavior for multiple elements with the same id, but Mozilla-based browsers will return the first element with specified id. - See Also
Document.getElementsByTagName | Element.getElementsByTagName | HTMLDocument.getElementsByName
- Availability
HTML DOM Level 2 | W3C
getElementsByTagName(String tagname) : static Array
Returns an array of Element nodes with the specified tag name.
| String | tagname | Tag name of the elements to return. Specify "*" to return all tags. (one-or-more) |
-
Using getElementsByTagName
// Assume there is only one in the document var body = document.getElementsByTagName("body").item(0); var paragraphs = body.getElementsByTagName("p");For additional examples, see the quirksmode test page:
- Remarks
-
Returns a list of elements in the document that have the specified
tagName. The returnedNodeListis sorted in the order the elements were found during a depth-firstpreorder traversalthrough the node tree. - See Also
Document.getElementById | Element.getElementsByTagName | HTMLDocument.getElementsByName
- Availability
HTML DOM Level 2 | W3C
getElementsByTagNameNS(String namespaceURI, String localName) : static Array
Returns the Element nodes with the specified element name and namespace.
| String | namespaceURI | Namespace of the elements to return. Specify "*" to return all tags. |
| String | localName | Tag name of the elements to return (minus the namespace prefix). Specify "*" to return all tags. |
-
Using getElementsByTagNameNS
var commands = document.getElementsByTagNameNS( 'http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul', 'command' ); - Remarks
-
Like
getElementsByTagName , this method returns aNodeListof elements found in the current document that match the specified tag name. However, this version of the method takes both anamespace URIandlocal nameof the element's tag name. - See Also
- Availability
HTML DOM Level 2 | W3C
getSelection() : String
Returns the text currently selected by the user.
- Remarks
- Netscape only. Supported in NS4+.
importNode(Object importedNode, Boolean deep) : static Node
Imports a node from a different document.
| Object | importedNode | Node to import. |
| Boolean | deep | If true, indicates that all child nodes of the import node should be imported as well. |
- Remarks
-
importNodeis similar tocloneNode, except thatimportNodeworks across documents.importNodeattempts to copy as much information about a node as possible, although different documents may be of different types (e.g. XML and HTML) or have different DTD's. - Throws
- Raises a NOT_SUPPORTED_ERR error if the node type being imported is not supported by the current document.
- See Also
- Availability
HTML DOM Level 2 | W3C
isSupported(String feature, [String version]) : Boolean
Returns true if the specified feature and version are supported.
| String | feature | Name of the feature. |
| String | version | Version of the feature. (optional) |
- Remarks
- Tests whether a node supports the specified feature. Similar to the
DOMImplementation.hasFeaturemethod and takes the same feature names. If version is null, returns true if any version of the feature is supported. - See Also
- Availability
HTML DOM Level 2
open([String mimeType,] [String name,] [String features,] [Boolean replace]) : void
Opens the document for writing.
| String | mimeType | MIME Type for the new document. IE only. (optional) |
| String | name | Specifies the new name for the document. Always use with mimeType. IE only. (optional) |
| String | features | Specifies any window-like features the document should have. Always use with mimeType. IE only. (optional) |
| Boolean | replace | If true, specifies that the new document should replace the current document in the browser history. Always use with mimeType. IE only. (optional) |
- Remarks
- Only use the parameters
mimeType,name,features, and replace with IE. If you use any of the parameters,mimeTypebecomes a required parameter. If you are not coding strictly for IE, do not pass any parameters to theopenmethod. - Availability
HTML DOM Level 1
queryCommandEnabled(String command) : Boolean
Returns true if the specified command is enabled.
| String | command | Command to check. |
quertyCommandIndeterm(String command) : Boolean
Returns true if the specified command is in an indeterminate state.
| String | command | Command to check. |
queryCommandState(String command) : Boolean
Returns true if the specified command has been executed on the object.
| String | command | Command to check. |
queryCommandSupported(String command) : Boolean
Returns true if the specified command is supported.
| String | command | Command to check. |
queryCommandValue(String command) : Object
Returns the value of the specified command for the document. Returns false if the command is not supported.
| String | command | Command to check. |
recalc([Boolean forceAll]) : void
Reevaluates all dynamic properties in the document.
| Boolean | forceAll | If true, forces all dynamic properties in the document to be reevaluated. If false (default), reevaluates only the dynamic properties that have changed. (optional) |
releaseEvents(Number eventMask) : Object
Sets the document to stop capturing the specified type of events.
| Number | eventMask | Bitmask containing the events to stop capturing. |
- Remarks
- Netscape only. Supported in NS4+.
- See Also
routeEvent(Object event) : Object
Routes the specified event to the next event handler.
| Object | event | Instance of the event to route. |
- Remarks
- Netscape only. Supported in NS4+.
- See Also
selection() : Object
Gives information about the currently selected objects in the document.
- Remarks
- IE only. Supported in IE4+.
write(String string) : Object
Writes the specified string of text to the end of the document.
| String | string | Text to append to the document. (one-or-more) |
Using write
document.write("Today's date is " + new Date());- See Also
- Availability
HTML DOM Level 1 | W3C
writeln(String string) : Object
Writes the specified string of text to the end of the document and adds a newline character at the end of the text.
| String | string | Text to append to the document. (one-or-more) |
Using write
document.writeln("Today's date is " + new Date());- See Also
- Availability
HTML DOM Level 1 | W3C
