tags:

views:

36

answers:

3
<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 I get the childNodes.nodevalue "This is a sample of some HTML you might have in your document"

A: 

try document.getElementsByTagName("p")[0].innerText.

Daniel A. White
No. said "undefined"
Jason
+1  A: 
var p = document.getElementsByTagName('p')[0],
    txt = p.innerText || p.textContent;

alert(txt);
J-P
it Works well .
Jason
thanks a lot. it is working
Jason
A: 

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);"/>
Kate