<span>paragraph1</span>
<span>paragraph2</span>
<span><strong>paragraph3</strong></span>
<button type="button" name="button" onclick="getname()"></button>
< script type = "text/javascript" >
function getname() {
var a = document.getElementsByTagName("p")[0];
alert(a.innerHTML);
alert(a.innerText);
alert(a.firstChild.nodeName); //-sharptext
alert(a.firstChild.nodeValue);//null
alert(a.lastChild.nodeValue);//null
}
there is no answer after searching for a long time. I"d like to ask
Q1:
.firstChild
is it a special and unique syntax or is it only used to select the first child element? What if I want to select paragraph2
in
?
Q2:
check MDN, and give me only one answer:
"alert (a.firstChild.nodeName)
will display"- sharptext", because a newline character and multiple spaces act as a text node before thetag and tag."
does a space count as a node? Does a line break count as a node? Does an element tag count as a node? Text is also a node?
I"m a little confused. Are they mixed? Are they all child nodes of object elements? So what"s their order?