jQuery javascript regex Replace <br> with \n -
how write regex replace <br />
or <br>
\n
. i'm trying move text div textarea, don't want <br>
's show in textarea, want replace \n
.
var str = document.getelementbyid('mydiv').innerhtml; document.getelementbyid('mytextarea').innerhtml = str.replace(/<br\s*[\/]?>/gi, "\n");
or using jquery:
var str = $("#mydiv").html(); var regex = /<br\s*[\/]?>/gi; $("#mydiv").html(str.replace(regex, "\n"));
edit: added i
flag
edit2: can use /<br[^>]*>/gi
match between br
, slash
if have example <br class="clear" />
Comments
Post a Comment