Answers for "js remove html tags from string"

9

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 &#169; 2017</p>\n </div>";

var stripedHtml = htmlString.replace(/<[^>]+>/g, '');
var decodedStripedHtml = he.decode(stripedHtml);

// Hello World
// This is the text that we should get.
// Our Code World &#169; 2017
console.log(stripedHtml);

// Hello World
// This is the text that we should get.
// Our Code World © 2017
console.log(decodedStripedHtml);
Posted by: Guest on February-18-2020
3

javascript remove html from text

//remove html tags from a string, leaving only the inner 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!"
Posted by: Guest on July-31-2019
-1

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);
Posted by: Guest on January-07-2021

Code answers related to "js remove html tags from string"

Code answers related to "Javascript"

Browse Popular Code Answers by Language