Online Forum To Support Coders With Technical Assistance - Read Write Execute

Strip HTML Tags using Javascript

Aman Agrawal
Aman Agrawal
Published on April 7, 2018 · 1 min read

So folks, sometimes it happens that you are saving some text with formatted data like HTML string but while displaying you don’t want to display it not as string but as formatted text.i.e. want to strip  HTML tags from the content here is the slution for it:

 


function stripTags(html) {
var tmp = document.createElement("DIV");
tmp.innerHTML = html;
return tmp.textContent || tmp.innerText || "";
}

Was this article helpful?
Aman Agrawal

Aman Agrawal

Author & Senior Engineer at CodeExecute

Writing practical engineering guides, debugging real-world bottlenecks, and creating free tools for developer productivity.

← Previous Article Remove default jquery from wordpress Next Article → Single Page Application vs Multi Page Application (SPA vs MPA)