且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用Javascript / jQuery从div内容中去除HTML标签?

更新时间:2023-10-31 12:25:40

使用正则表达式。



var body =< p> test< / p>
var result = body.replace(regex,);

alert(result);

这里是 DEMO



希望这有助于您。


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 can I achieve this?

use the regular expression.

var regex = /(<([^>]+)>)/ig
var body = "<p>test</p>"
var result = body.replace(regex, "");

alert(result);

HERE IS THE DEMO

Hope this helps.