javascript - Jquery Replace br tags -
i have text several line break tags so
<br></br>
and several double line breaks so
<br></br><br></br>
i want rid of single <br></br>
, want keep double ones using jquery or jscript how can tell when used .filter("<br></br>")
did not work because got rid of both
is there way replace instances of <br></br><br></br>
replacewith? or other way
the easiest way three-step process:
text = text. replace(/<br><\/br><br><\/br>/g, '____magicmarker____'). replace(/<br><\/br>/g, ''). replace(/____magicmarker____/g, '<br></br><br></br>')
hoping ____magicmarker____
never, nor ever, part of text. possibility (and better, foolproof one) be:
text = text.replace(/(<br><\/br>)+/g, function(all, once) { if (all == once) return ""; return all; });
note written assuming premise in question correct: have text (i.e. string). if have document fragment, want operation on innerhtml
.
Comments
Post a Comment