1var htmlString= "<div>\n <h1>Hello World</h1>\n <p>This is the text that we should get.</p>\n <p>Our Code World © 2017</p>\n </div>";
2
3var stripedHtml = htmlString.replace(/<[^>]+>/g, '');
4var decodedStripedHtml = he.decode(stripedHtml);
5
6// Hello World
7// This is the text that we should get.
8// Our Code World © 2017
9console.log(stripedHtml);
10
11// Hello World
12// This is the text that we should get.
13// Our Code World © 2017
14console.log(decodedStripedHtml);
1//remove html tags from a string, leaving only the inner text
2function removeHTML(str){
3 var tmp = document.createElement("DIV");
4 tmp.innerHTML = str;
5 return tmp.textContent || tmp.innerText || "";
6}
7var html = "<div>Yo Yo Ma!</div>";
8var onlyText = removeHTML(html); "Yo Yo Ma!"
9
1function stripHtml(html)
2{
3 let tmp = document.createElement("DIV");
4 tmp.innerHTML = html;
5 return tmp.textContent || tmp.innerText || "";
6}
7