Skip to content

Instantly share code, notes, and snippets.

@vyspiansky
Created January 4, 2020 17:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vyspiansky/9950e9fff397382047d09fbee1d41387 to your computer and use it in GitHub Desktop.
Save vyspiansky/9950e9fff397382047d09fbee1d41387 to your computer and use it in GitHub Desktop.
JavaScript: remove HTML tags
function strip(html) {
const tempWrapper = document.createElement("DIV");
tempWrapper.innerHTML = html;
return tempWrapper.textContent || tempWrapper.innerText;
}
const html = '<p><strong>Lorem Ipsum<strong> is simply dummy text of the printing and typesetting industry.</p>';
const plainText = strip(html);
console.log(plainText);
// Output:
// Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment