<p title="The test paragraph">This is a sample of some <b>HTML you might<br>have</b> in your document</p>
txt=document.getElementsByTagName("p")[0].childNodes[0].nodeValue;
alert("<p>The text from the intro paragraph: " + txt + "</p>");
it doesn't work.
How can 开发者_JAVA百科I get the childNodes.nodevalue "This is a sample of some HTML you might have in your document"
var p = document.getElementsByTagName('p')[0],
txt = p.innerText || p.textContent;
alert(txt);
try document.getElementsByTagName("p")[0].innerText
.
I try you example and it is work fine, but you should replase "" in etElementsByTagName("p") by ''. My code is:
<p title="The test paragraph">This is a sample of some <b>HTML you might<br>have</b> in your document</p>
<input type="button" onclick="alert(document.getElementsByTagName('p')[0].childNodes[0].nodeValue);"/>
精彩评论