This is element x
. Its nodeName is <p>
,
it has an align
attribute and its last child is a comment, which y
refers to.
This page tests nodeName
, nodeType
, nodeValue
and
tagName
of element nodes, attribute nodes, text nodes, comment nodes, and the document node.
nodeName of element (correct answer: P)
alert(x.nodeName);
nodeName of attribute (correct answer: align)
alert(x.getAttributeNode('align').nodeName);
nodeName of text node (correct answer: #text)
alert(x.firstChild.nodeName)
nodeName of comment node (correct answer: #comment)
alert(y.nodeName)
nodeName of document (correct answer: #document)
alert(document.nodeName)
nodeType of element (correct answer: 1)
alert(x.nodeType)
nodeType of attribute (correct answer: 2)
alert(x.getAttributeNode('align').nodeType)
nodeType of text node (correct answer: 3)
alert(x.firstChild.nodeType)
nodeType of comment (correct answer: 8)
alert(y.nodeType)
nodeType of document (correct answer: 9)
alert(document.nodeType)
alert(x.getAttributeNode('align').nodeValue)
alert(x.firstChild.nodeValue)
alert(y.nodeValue)
Now let's change the nodeValue
.
x.getAttributeNode('align').nodeValue = 'right'
x.firstChild.nodeValue = 'Changed nodeValue '
y.nodeValue = 'Changed nodeValue '
alert(x.tagName)
alert(x.getAttributeNode('align').tagName)
alert(x.firstChild.tagName)
alert(y.tagName)
alert(document.tagName)