asp.net.ph

Skip Navigation Links

nodeName Property

DHTML Object Properties   DHTML Objects


DOM Level 1 Specification.

Returns the name of the node.

Syntax


HTML N/A
Script [ sName = ] object.nodeName

Possible Values


sName String. The name of the node.

The property is read-only and always contains a non-empty string.

Remarks

The nodeName property contains the qualified name for the element, attribute, or entity reference, or a fixed string for other node types.

The node name value varies, depending on the nodeType property:

  • If nodeType is ATTRIBUTE, contains the name of the attribute.
  • If nodeType is CDATA_SECTION, contains the literal string "#cdata-section".
  • If nodeType is COMMENT, contains the literal string "#comment".
  • If nodeType is DOCUMENT, contains the literal string "#document".
  • If nodeType is DOCUMENT_TYPE, contains the name of the document type; for example, xxx in .
  • If nodeType is DOCUMENT_FRAGMENT, contains the literal string "#document-fragment".
  • If nodeType is ELEMENT, contains the name of the HTML/XML tag, with any namespace prefix included if present.
  • If nodeType is ENTITY, contains the name of the entity.
  • If nodeType is ENTITY_REFERENCE, contains the name of the entity referenced. Note that the name does not include the leading ampersand or the trailing semicolon. The name includes the namespace if one is present.
  • If nodeType is NOTATION, contains the name of the notation.
  • If nodeType is PROCESSING_INSTRUCTION, contains the target; the first token following the <? characters.
  • If nodeType is TEXT, contains the literal string "#text".

The nodeName property is equivalent to the tagName property, if the nodeType is an element.

Example

The following examples demonstrate implementation of the nodeName attribute.

The sample below retrieves the nodeName value of a particular element, in this case the firstChild of the documentElement property of this document.

var nName = document.documentElement.firstChild.nodeName;
alert ( nName );

 Show me 

The sample below shows how to retrieve the nodeName values of all the nodes in the BODY of this document. A NodeList object is created, and a loop iterates thru all the objects in the NodeList, retrieving each object’s nodeName.

function nodeNameDemo ( ) {
var all, list;
all = document.body.childNodes;
list "nodeNames of all childNodes of the BODY\n';
for ( n = 0; n < all.length; n++ ) {
  list + "\nchildNode ' + n + ' ' + all [ n ] .nodeName;
  }
return ( list );
}

Press your browser back button after.

 Show me 

See Also

nodeType, nodeValue



>

© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note