HTML code script for a HTML tags remover

Created on 3 July, 2024 • 153 views

HTML code script for a HTML tags remover

<script>

function removeTags(html) {

 const parser = new DOMParser();

 const doc = parser.parseFromString(html, 'text/html');

 return doc.body.textContent || "";

}


// Example usage

const htmlString = "<p>This is a <b>paragraph</b> with some <em>emphasis</em>.</p>";

const textContent = removeTags(htmlString);

console.log(textContent); // Output: This is a paragraph with some emphasis.

</script>