Strip HTML from Text JavaScript

前端 未结 30 3584
北荒
北荒 2020-11-21 05:08

Is there an easy way to take a string of html in JavaScript and strip out the html?

30条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-21 05:36

    from CSS tricks:

    https://css-tricks.com/snippets/javascript/strip-html-tags-in-javascript/

    const originalString = `
      

    Hey that's somthing

    `; const strippedString = originalString.replace(/(<([^>]+)>)/gi, ""); console.log(strippedString);

提交回复
热议问题