Jerry1
Jerry1

Reputation: 372

html textarea replace br tag to \n

I need to edit row's cell in table with using new lines characters. Editation of these cells are make by textarea with jQuery. Problem is, that textarea using \n for new line, but html page using br tag.

There is my code:

$('#id_textarea').val(cell_string.replace(/<br>\*/gi,'\n'));

I know, that string has br tag likes (NOTE-1):

<br></br>

I tried:

$('#id_textarea').val(cell_string.replace(/**<br></br>**\*/gi,'\n'));

But still cannot understand, how the regular expression works.

And there is picture of my issue.

NOTE-1 - these br tags are make by:

content = content.replace(/\n/g, "<br>");

IN DB there is:

<br>

In Firefox:

<br></br>

In Chrome:

<br>

Why?

Upvotes: 4

Views: 8779

Answers (1)

xdazz
xdazz

Reputation: 160833

Your regex is not right, try:

$('#id_textarea').val(cell_string.replace(/<br *\/?>/gi, '\n'));

THE DEMO.

Upvotes: 7

Related Questions