When trying to emulate php's nl2br() function in javascript, I ran into something quite disturbing.

Code:
cms.t.value = cms.t.value.replace(/\n/gi, '<br />\n');
Using this piece of code, I was really surprised that the newlines weren't preceded by <br />, but by <br>. I really don't understand why that would happen. Why can't I decide my own replacement string? .