I’ve read several posts on this subject, but none which properly worked
I’m trying to replace the hard returns in a text area with <br/> on button click.
Is this possible? Here is what I have currently:
<script>
$('document').ready(function () {
$('#button').click(function(){
$('#y').val().replace(/\r\n/g, "</p><br/><p> ");
var y = '<p> '+$('#y').val()+'</p>';
console.log(y)
});
});
</script>
<TEXTAREA id="y" ROWS="3" COLS="25">
</TEXTAREA>
<br><br>
<INPUT TYPE="submit" id="button">
use
/\n/ginstead of/\r\n/g. You only need to match\nnot\nwhen preceded by a\r. You also need to store the result because.replace()returns the result (it doesn’t apply it to the current value). So:follow-up example: http://jsfiddle.net/qTpm6/