You are here: Reference > JavaScript > client-side > HTML DOM > objects > attribute

attribute object

Browser support:
Represents an attribute of an element in an HTML or XML document.

Syntax:

Methods that return the object:
+object.createAttribute (attributeName)
Related objects:
+object.createAttributeNS (namespaceURI, attributeName)
Related objects:
+object.getAttributeNode (attributeName)
+object.getAttributeNodeNS (namespaceURI, attributeName)
attributes.getNamedItem (attributeName)
attributes.getNamedItemNS (namespaceURI, attributeName)
attributes.item (index)
+object.removeAttributeNode (attributeNode)
attributes.removeNamedItem (attributeName)
attributes.removeNamedItemNS (namespaceURI, attributeName)
+object.setAttributeNode (attributeNode)
+object.setAttributeNodeNS (attributeNode)
attributes.setNamedItem (attributeNode)
attributes.setNamedItemNS (attributeNode)
The base interface, through which you can add new functionalities to the attribute object, is the Attr interface.

Possible members:

Properties:
baseName
Returns the local part of the qualified name of the current node.
baseURI
10
Returns the base URL for the object.
childNodes
Represents a collection of all nodes that are direct descendants of an element.
dataType
Sets or returns the data type for the current element or attribute.
expando
Sets or returns a Boolean value that indicates whether additional properties can be used within the object.
firstChild
Returns a reference to the first child of the current element.
isId
5
Returns whether the current attribute node is an id attribute or not.
lastChild
Returns a reference to the last child of the current element.
localName
9
Returns the local part of the qualified name of the current node.
name
Returns the name of the current attribute.
namespaceURI
Sets or returns the namespace URI of the current node.
nextSibling
Returns a reference to the next child of the current element's parent.
nodeName
Returns the name of the current node.
nodeType
Returns an integer that indicates the type of the node.
nodeTypedValue
Sets or returns the value of the node in its data type. The data type of a node can be defined with the dataType property.
nodeTypeString
Returns the type of the current node as a string.
nodeValue
Sets or returns the value of the current node.
ownerDocument
Returns the document object that contains the current node.
ownerElement
8
Returns the element object that contains the current attribute.
parentNode
Returns the parent element of the current node in the DOM hierarchy.
prefix
Sets or returns the namespace prefix of the current node.
previousSibling
Returns a reference to the previous node of the current element's parent.
specified
Retrieves a Boolean value that indicates whether an attribute is specified.
textContent
9
Sets or returns the text content of an element including the text content of its descendants.
value
Sets or returns the value of the current attribute.
Methods:
appendChild
Inserts an element after the last child of the current element.
cloneNode
Returns an exact copy of the current node.
compareDocumentPosition
9
Compares the placement of the specified node with the current node in the DOM hierarchy.
hasChildNodes
Returns whether the current node has any child nodes or not.
insertBefore
Inserts an element before the specified child of the current element.
isDefaultNamespace
9
Returns whether the specified namespace URI is the default namespace in the scope of the current node.
isEqualNode
9
Returns whether the current node is equal to the specified one.
isSameNode
9
Returns whether the current node is the same node as the specified one.
isSupported
9
Returns whether the specified DOM module and version is supported by the current node.
lookupNamespaceURI
9
Retrieves the namespace URI associated with the specified namespace prefix in the scope of the current node.
lookupPrefix
9
Retrieves the namespace prefix associated with the specified namespace URI in the scope of the current node.
normalize
9
Puts the subtree that belongs to the current node into a 'normalized' form.
removeChild
Removes the specified child node from the current element.
replaceChild
Replaces the specified child element of the current element with a new element.

Example HTML code 1:

This example illustrates the use of the attribute object:
<head>
    <script type="text/javascript">
        function GetAttr (elem) {
            var attr = elem.getAttributeNode ("onclick");
            alert ("nodeName: " + attr.nodeName + 
                    "\n nodeType: " + attr.nodeType + 
                    "\n nodeValue: " + attr.nodeValue);
        }
    </script>
</head>
<body>
    <button onclick="GetAttr (this);">Get the onclick attribute!</button>
</body>
Did you find this example helpful? yes no

External links:

User Contributed Comments

Post Content

Post Content