user3418849 user3418849 - 6 months ago 32
jQuery Question

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

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?

Answer

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.