To get paragraph text inside an element with JavaScript, we can use the innerHTML
property of the element.
For instance, if we have:
<p>
hello world
</p>
Then we write:
const text = document.querySelector('p').innerHTML;
console.log(text)
to get the p element with document.querySelector
.
Then we use the innerHTML
property to return the text.
Therefore, from the console log, we see that text
is:
hello world