Javascript – how to view text inside DOM element

Javascript DOM method textContent can be used to get the text content inside a DOM. This can be useful to obtain content from a web page. Here is an example.

<div id="id1">
  <a href="/">link text</a>
<textarea id="ta1" rows="5">-</textarea>
<script type="text/javascript">
window.addEventListener("load", showText);
function showText() {
  var text = document.querySelector("#id1").textContent;
  document.querySelector("#ta1").value = text;

Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit


Click here to write/view comments