JS

HOW TO STRIP OR REMOVE HTML TAGS IN JAVASCRIPT

ORIGINAL STRING var str = "<p>FOO</p>";   CLEANED STRING var clean = str.replace(/(<([^>]+)>)/gi, "");

REGULAR EXPRESSION

01

ORIGINAL STRING var str = "<p>FOO</p>";   DUMMY ELEMENT let ele = document.createElement("div"); ele.innerHTML = str;   CLEANED STRING var clean  = ele.textContent;

TEXT CONTENT

02

ORIGINAL STRING var str = "<p>FOO</p>";   PARSED DOM let parsed = new DOMParser(). parseFromString(str, 'text/html');   CLEANED STRING var clean  = parsed.body.textContent;

DOM PARSER

03