replace html tags in string 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: remove html between 2 tags javas
var myString = "<table><tr><td>Some text ...<a href='#'>label...</a></td></tr></table";
myString += "<table><tr><td>Some text ...<a href='#'>label...</a></td></tr></table";
myString += "<table><tr><td>Some text ...<a href='#'>label...</a></td></tr></table";
console.log(myString);
var anchorTagsRemoved = myString.replace(/<a.*>.*?<\/a>/ig,'');
console.log(anchorTagsRemoved);