[Home] >  DOM >  Strip HTML from a given text

Strip HTML from a given text

JavaScript version

const stripHtml = (html) => new DOMParser().parseFromString(html, 'text/html').body.textContent || '';

TypeScript version

const stripHtml = (html: string): string => new DOMParser().parseFromString(html, 'text/html').body.textContent || '';