Get The Text Inside The Element
First Text
n.b. in the code above it's selecting by tag name, so it returns an array of matching elements
So in your example, using .innerHTML with give you the P tags content, including any html tags etc.
if you want just the content, you can use .textContent
console.log(document.getElementsByTagName('p')[0].textContent);
This wont give you the inner html tags
n.b. there is also the innerText method, However this isnt supported accross browsers.
Solution 2:
You can change according to the tag you need, but basically this will do the trick:
document.getElementsByTagName('p')[0].innerTextSolution 3:
InnerText should be a good solution.
console.log(document.getElementsByTagName('p')[0].innerText);<pclass="MsoNormal"style="margin-bottom:0cm;margin-bottom:.0001pt;text-align:
justify;line-height:normal">
First Text
<spanlang="EN-US"style="font-size:12.0pt;
font-family:"Times New Roman","serif"">
Second Text</span></p>
Post a Comment for "Get The Text Inside The Element"