Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
173
rated 0 times [  179] [ 6]  / answers: 1 / hits: 28778  / 11 Years ago, thu, may 23, 2013, 12:00:00

I want to remove all the html tags except <br> or <br/> tags from a string using javascript.
I have seen many questions like this but their answers will remove all the html tags including <br> and <br/> tags.



Does anyone knows a regex to do this?


More From » html

 Answers
18

Try This



 function remove_tags(html)
{
var html = html.replace(<br>,||br||);
var tmp = document.createElement(DIV);
tmp.innerHTML = html;
html = tmp.textContent||tmp.innerText;
return html.replace(||br||,<br>);
}

[#78069] Wednesday, May 22, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
trayvon

Total Points: 35
Total Questions: 117
Total Answers: 88

Location: Guernsey
Member since Tue, Jul 6, 2021
3 Years ago
;