0

I have done text replacement in Javascript such that the <br /> tag will be replaced by the \n\r . This seems to work in IE8.0 but not in chrome and firefox. why is that so? How can I make it work in chrome and firefox. Why does chrome and firefox not consider <br/> tags as <br/> but rather <br>?

2
  • 1
    What do you need this for? Can you elaborate on your situation? There may be a better/easier way for what you want to do.
    – Pekka
    Oct 6, 2011 at 9:31
  • In the future, you really need to show the code that isn't working.
    – user50049
    Oct 6, 2011 at 13:17

1 Answer 1

2

This seems to be working fine everywhere:

"Hello<br />World".replace(/<br\s*\/?>/ig, "\r\n");
2
  • Sometimes simple mistake happens like : Some one can use "</br>" , in this case use replace(/<\s*\/?br>/ig, "\r\n")
    – eegloo
    Nov 11, 2013 at 10:24
  • 1 this the best solution Jul 18, 2017 at 13:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.