nodeName and nodeValue

In this chapter you will learn:

  1. Get the nodeName and nodeValue using Javascript

nodeName and nodeValue Properties

nodeName and nodeValue give specific information about the node. The values of nodeName and nodeValue are dependent on the node type.

<!DOCTYPE HTML> <!--   j  av a2s. co  m-->
<html> 
    <body> 
        <pre id="results"></pre> 
        <script> 
            var resultsElement = document.getElementById("results"); 
            document.writeln(resultsElement.nodeType); 
            document.writeln(resultsElement.nodeName); 
        </script> 
    </body> 
</html>

Click to view the demo

For elements, nodeName is always equal to the element's tag name, and nodeValue is always null.

Next chapter...

What you will learn in the next chapter:

  1. How to use childNodes to get node relationships
  2. How to get child node by index
Home » Javascript Tutorial » DOM
Document Object Model
Node Type
nodeName and nodeValue
childNodes
parentNode
previousSibling and nextSibling
lastChild and firstChild
appendChild
insertBefore
ownerDocument
removeChild
replaceChild
Text
NodeList Length
DOM classes