开发者

html tag in childNodes (how can i get NodesValue)

开发者 https://www.devze.com 2022-12-22 07:16 出处:网络
<p title=\"The test paragraph\">This is a sample of some <b>HTML you might<br>have</b> in your document</p>
<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);"/>
0

精彩评论

暂无评论...
验证码 换一张
取 消