How to strip HTML tags from div content using Javascript/jQuery?

前端 未结 6 913
梦毁少年i
梦毁少年i 2020-12-31 22:24

I had made one div tag and stored its contents in a variable. If this tag contains p,b or any other tags then it should be removed from string. How

6条回答
  •  时光取名叫无心
    2020-12-31 22:40

    use the regular expression.

    var regex = /(<([^>]+)>)/ig
    var body = "

    test

    " var result = body.replace(regex, ""); alert(result);

    HERE IS THE DEMO

    Hope this helps.

提交回复
热议问题