Answers for "convert html entity to text javascript"

4

js convert html to text

// To remove all HTML tags use the ".replace(/<[^>]+>/g, '')" method.
let myHTML= "<div><h1>Jimbo.</h1>\n<p>That's what she said</p></div>";
let strippedHtml = myHTML.replace(/<[^>]+>/g, '');
console.log(stripedHtml); // Jimbo. That's what she said
Posted by: Guest on September-06-2021
0

Javascript convert html entity to string

const htmlEntities = {
    "&": "&amp;",
    "<": "&lt;",
    ">": "&gt;",
    '"': "&quot;",
    "'": "&apos;"
  };
return str.replace(/([&<>\"'])/g, match => htmlEntities[match]);
}
Posted by: Guest on August-18-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language