Jump to content

Replacing Multiple Line Breaks


ldsmike88

Recommended Posts

I have a line of code that looks something like this:

 

var myTextareaValue = textareaValue.replace('\n','<br/ >');

 

That works fine when I only have one line break at a time. But if I have multiple line breaks it only puts one <br/ > tag in instead of two or three. How can I make it so it will put in the right amount of break tags. Thanks!

 

Michael

 

(I know my break tags in this forum aren't formatted correctly, but if they are they actuly are break tags and you can't see them.)

Link to comment
Share on other sites

change

var myTextareaValue = textareaValue.replace('\n','<br/ >');

 

to

 

var myTextareaValue = myTextareaValue.replace(/\n/g, /<b r>/ );

 

 

The g switch makes the changes global.

I'm not certain if you can escape the forward slash in the <b r /> replacement section

but if you can it'll probably look like /<br \/>/

I added a space in the br to stop the line from breaking

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.