javascript strip tags code example
Example 1: javascript strip html tags from string
var 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>";
var stripedHtml = htmlString.replace(/<[^>]+>/g, '');
var decodedStripedHtml = he.decode(stripedHtml);
console.log(stripedHtml);
console.log(decodedStripedHtml);
Example 2: strip html tags javascript
originalString.replaceAll(/(<([^>]+)>)/gi, "")
Example 3: javascript remove html from text
function removeHTML(str){
var tmp = document.createElement("DIV");
tmp.innerHTML = str;
return tmp.textContent || tmp.innerText || "";
}
var html = "<div>Yo Yo Ma!</div>";
var onlyText = removeHTML(html); "Yo Yo Ma!"
Example 4: how to strip html tags in javascript
function stripHtml(html)
{
let tmp = document.createElement("DIV");
tmp.innerHTML = html;
return tmp.textContent || tmp.innerText || "";
}
Example 5: js strip_tags
let strippedString = originalString.replace(/(<([^>]+)>)/gi, "");