codescracker


javascript

JavaScript DOM Interfaces



« Previous Tutorial Next Tutorial »


The DOM API provides interfaces to implement DOM. Each interface is associated with a particular type of node that is defined in the inheritance hierarchy, which are described in the following table:

Interface Description
The DOMException Interface This interface represents some exceptions and errors that occur due to an invalid DOM or when a non-existing node is passed as an argument of a method
The DOMImplementation Interface This interface provides some methods that help in performing certain operations that are not dependent on any document or instance of DOM
The DocumentFragment Interface This interface is used for temporarily storing the structure of DOM
The Document Interface This interface is the root node in the DOM tree. It defines the documentElement property of the document, which returns the root node by looping through all the child nodes of the Document nodes to test whether or not they are Element nodes
The Node Interface This interface is the base interface in the DOM tree. It means that all the other interfaces are derived from the Node interface
The NodeList Interface This interface provides an ordered collection of nodes without defining the method for implementing these nodes in DOM
The NamedNodeMap Interface The interface represents an unordered collection of nodes that can be accessed by their name
The CharacterData Interface This interface allows you to extend the node by providing a set of properties and methods, which you can use to access the character data in the DOM
The Attr Interface This interface represents an attribute of an element. It inherits the Node interface
The Element Interface This interface represents an element in an HTML document.
The Text Interface This interface inherits from the CharacterData interface and is used to represent the textual content of an Element or Attr node
The Comment Interface This interface is inherited from the CharacterData interface and is used to represent the comments of the XML or XHTML documents

JavaScript DOMException Interface Exception Code

Here is the table lists exception code of DOMException interface in JavaScript.

Code Exception
1 INDEX_SIZE_ERR exception
2 DOMSTRING_SIZE_ERR exception
3 HIERARCHY_REQUEST_ERR exception
4 WRONG_DOCUMENT_ERR exception
5 INVALID_CHARACTER_ERR exception
6 NO_DATA_ALLOWED_ERR exception
7 NO_MODIFICATION_ALLOWED_ERR exception
8 NOT_FOUND_ERR exception
9 NOT_SUPPORTED_ERR exception
10 INUSE_ATTRIBUTE_ERR exception
11 INVALID_STATE_ERR exception
12 SYNTAX_ERR exception
13 INVALID_MODIFICATION_ERR exception
14 NAMESPACE_ERR exception
15 INVALID_ACCESS_ERR exception

JavaScript Node Interface Properties and Methods

The table given below describes properties of Node interface in JavaScript.

Property Description
nodeType returns an integer value that represents the node type
nodeName returns the name of the node
nodeValue returns the value of the node
attributes returns an array of Attr objects that represents the attributes of the current node
parentNode returns the parent node of the current node if it exists, otherwise it returns a null value
childNodes returns an array of Node objects that represents the child nodes of the current node
firstChild returns a Node object that represents the first child of the current node, otherwise it returns a null value
lastChild returns a Node object that represents the last child of the current node, otherwise it returns a null value
localName returns a qualified name of the current node
namespaceURI returns the namespace URI of the current node
nextSibling returns the node that immediately follows the current node
ownerDocument returns a Document object associated with the current node
prefix returns the namespace prefix of the current node
previousSibling returns the node immediately preceding the current node

The following table lists the methods of the Node interface in JavaScript.

Method Description
appendChild adds a new child node at the end of the list of the child nodes
cloneNode creates a duplicate node of the current node
hasAttributes returns true if the node has an attribute
hasChildNodes returns true if the node has child nodes
insetBefore inserts a new child node before the current child node
inSupported checks whether a specified feature is implemented by the DOM implementation and is supported by the current node
normalize places the sub-tree of the current node in state where the structural nodes separated by the text nodes
removeChild removes an existing child node from the list of child nodes
replaceChild replaces an existing child node with the new node

JavaScript NamedNodeMap Interface Methods

Here is the table describes the methods of the NamedNodeMap interface in JavaScript.

Method Description
getNamedItem retrieves a node from the collection on the basis of its name
getNamedItemNS retrieves a node from the collection on the basis of its local name and namespace URI
item returns an item from the collection on the basis of its index number
removeNamedItem removes a node from the collection on the basis of its name
removeNamedItemNS removes a node from the collection on the basis of its local name and namespace URI
setNamedItem adds a node in the collection by using its nodeName attribute
setNamedItemNS adds a node in the collection by using the namespaceURI and localName of the new node

JavaScript CharacterData Interface Methods

The table given below describes methods of the CharacterData interface in JavaScript.

Method Description
appendData appends string at the end of the character data of the current node
deleteData removes a range of 16-bit units from the current node
insertData inserts a string at the specified 16-bit unit offset
replaceData replaces the characters starting at the specified 16-bit unit offset with the specified string
substringData extracts a range of data from the node

JavaScript Document Interface Methods

The following table describes methods of Document interface in JavaScript.

Method Description
getElementByTagName returns an array of element objects that have a tag name similar to the specified name
getElementByTagNameNS returns an array of an element object whose name attribute's value matches the value of the argument of this method
getElementById returns the element object that has the same id, as specified in the argument

JavaScript Element Interface Methods

Here is the table describes methods of the Element interface in JavaScript.

Method Description
hasAttribute() returns true if the specified element has an attribute
getAttribute() returns the value of the attribute of the specified element
setAttribute() assigns the specified value to the specified attribute
removeAttribute() removes the specified attribute
getElementByTagName() returns an array of element objects whose name matches with that provided in the tagName attribute

JavaScript Attr Interface Properties

The following table describes properties of the Attr interface in JavaScript.

Property Description
name specifies the name of the attribute
value specifies the value of the attribute
ownerElement returns the element node of the Attr object
specified returns true if the attribute is set by the user or returns false if the attribute is set by the default value

« Previous Tutorial Next Tutorial »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test