|
|
Browser support:
Represents an attribute of an element in an HTML or XML document.
Syntax:
Methods that return the object:
| + | object.createAttribute (attributeName)
| |
|
| + | object.createAttributeNS (namespaceURI, attributeName)
| |
|
| + | object.getAttributeNode (attributeName)
| |
Related HTML objects:
a, abbr, acronym, address, applet, area, b, base, basefont, bdo, bgsound, big, blink, blockquote, body, br, button, caption, center, cite, code, col, colgroup, comment, dd, del, dfn, dir, div, dl, dt, em, embed, fieldset, font, form, frame, frameset, h1, h2, h3, h4, h5, h6, head, hr, html, i, iframe, img, input:button, input:checkbox, input:file, input:hidden, input:image, input:password, input:radio, input:range, input:reset, input:search, input:submit, input:text, ins, isindex, kbd, keygen, label, legend, li, link, listing, map, marquee, menu, meta, nobr, noframes, noscript, object, ol, optgroup, option, p, param, plaintext, pre, q, rt, ruby, s, samp, script, select, small, span, strike, strong, style, sub, sup, table, tbody, td, textarea, tfoot, th, thead, title, tr, tt, u, ul, var, wbr, xml, xmp
|
| + | object.getAttributeNodeNS (namespaceURI, attributeName)
| |
Related HTML objects:
a, abbr, acronym, address, applet, area, b, base, basefont, bdo, bgsound, big, blink, blockquote, body, br, button, caption, center, cite, code, col, colgroup, comment, dd, del, dfn, dir, div, dl, dt, em, embed, fieldset, font, form, frame, frameset, h1, h2, h3, h4, h5, h6, head, hr, html, i, iframe, img, input:button, input:checkbox, input:file, input:hidden, input:image, input:password, input:radio, input:range, input:reset, input:search, input:submit, input:text, ins, isindex, kbd, keygen, label, legend, li, link, listing, map, marquee, menu, meta, nobr, noframes, noscript, object, ol, optgroup, option, p, param, plaintext, pre, q, rt, ruby, s, samp, script, select, small, span, strike, strong, style, sub, sup, table, tbody, td, textarea, tfoot, th, thead, title, tr, tt, u, ul, var, wbr, xml, xmp
|
| | attributes.getNamedItem (attributeName) |
| | attributes.getNamedItemNS (namespaceURI, attributeName) |
| | attributes.item (index) |
| + | object.removeAttributeNode (attributeNode)
| |
Related HTML objects:
a, abbr, acronym, address, applet, area, b, base, basefont, bdo, bgsound, big, blink, blockquote, body, br, button, caption, center, cite, code, col, colgroup, comment, dd, del, dfn, dir, div, dl, dt, em, embed, fieldset, font, form, frame, frameset, h1, h2, h3, h4, h5, h6, head, hr, html, i, iframe, img, input:button, input:checkbox, input:file, input:hidden, input:image, input:password, input:radio, input:range, input:reset, input:search, input:submit, input:text, ins, isindex, kbd, keygen, label, legend, li, link, listing, map, marquee, menu, meta, nobr, noframes, noscript, object, ol, optgroup, option, p, param, plaintext, pre, q, rt, ruby, s, samp, script, select, small, span, strike, strong, style, sub, sup, table, tbody, td, textarea, tfoot, th, thead, title, tr, tt, u, ul, var, wbr, xml, xmp
|
| | attributes.removeNamedItem (attributeName) |
| | attributes.removeNamedItemNS (namespaceURI, attributeName) |
| + | object.setAttributeNode (attributeNode)
| |
Related HTML objects:
a, abbr, acronym, address, applet, area, b, base, basefont, bdo, bgsound, big, blink, blockquote, body, br, button, caption, center, cite, code, col, colgroup, comment, dd, del, dfn, dir, div, dl, dt, em, embed, fieldset, font, form, frame, frameset, h1, h2, h3, h4, h5, h6, head, hr, html, i, iframe, img, input:button, input:checkbox, input:file, input:hidden, input:image, input:password, input:radio, input:range, input:reset, input:search, input:submit, input:text, ins, isindex, kbd, keygen, label, legend, li, link, listing, map, marquee, menu, meta, nobr, noframes, noscript, object, ol, optgroup, option, p, param, plaintext, pre, q, rt, ruby, s, samp, script, select, small, span, strike, strong, style, sub, sup, table, tbody, td, textarea, tfoot, th, thead, title, tr, tt, u, ul, var, wbr, xml, xmp
|
| + | object.setAttributeNodeNS (attributeNode)
| |
Related HTML objects:
a, abbr, acronym, address, applet, area, b, base, basefont, bdo, bgsound, big, blink, blockquote, body, br, button, caption, center, cite, code, col, colgroup, comment, dd, del, dfn, dir, div, dl, dt, em, embed, fieldset, font, form, frame, frameset, h1, h2, h3, h4, h5, h6, head, hr, html, i, iframe, img, input:button, input:checkbox, input:file, input:hidden, input:image, input:password, input:radio, input:range, input:reset, input:search, input:submit, input:text, ins, isindex, kbd, keygen, label, legend, li, link, listing, map, marquee, menu, meta, nobr, noframes, noscript, object, ol, optgroup, option, p, param, plaintext, pre, q, rt, ruby, s, samp, script, select, small, span, strike, strong, style, sub, sup, table, tbody, td, textarea, tfoot, th, thead, title, tr, tt, u, ul, var, wbr, xml, xmp
|
| | 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 |
|
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 should be used within the object.
|
| firstChild |
|
Returns a reference to the first child of the current element.
|
| isId |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
Returns whether the specified namespace URI is the default namespace in the scope of the current node.
|
| isEqualNode |
|
Returns whether the current node is equal to the specified one.
|
| isSameNode |
|
Returns whether the current node is the same node as the specified one.
|
| isSupported |
|
Returns whether the specified DOM module and version is supported by the current node.
|
| lookupNamespaceURI |
|
Retrieves the namespace URI associated with the specified namespace prefix in the scope of the current node.
|
| lookupPrefix |
|
Retrieves the namespace prefix associated with the specified namespace URI in the scope of the current node.
|
| normalize |
|
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:
|
Share:
|
Digg
|
Del.icio.us
|
Reddit
|
Facebook
|
Twitter
|
Diigo
|
|
User Contributed Comments
|
|