Skip to content

Instantly share code, notes, and snippets.

@juanfernandes
Created September 2, 2013 09:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanfernandes/6410854 to your computer and use it in GitHub Desktop.
Save juanfernandes/6410854 to your computer and use it in GitHub Desktop.
Get text content from HTML with out html code.
Let's say you have the following HTML:
<div id="module">
<p>
This is some <b>example</b> text
<span>with some random markup.</span>
</p>
</div>
If you want to grab all the text content inside of #module, you can do this:
var module = document.getElementById("module");
var moduleText = module.textContent;
console.log(moduleText);
// result:
// "This is some example text with some random markup."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment