0

I have a textarea element and on top of it, I also have a div block that superimposed exactly over the textarea (eg:-facebook comment box).Everything is going cool and fine not until this line-breaks comes into the scene. So I'm trying to detect every single line breaks( natural word-wrap) in the text area and insert a <br/> tags into the div block whenever it encounters.

Actually, looping over the characters in the textarea could have solve the issue but this would overkill the process particularly when the value of the textarea happens to be very long.

The "wrap-hard" attribute of the html5 is exactly what I need it but that requires one to submit the form.

Can someone suggest an ideal way to detect natural line breaks in the textarea? Many thanks!!!

Pointy
  • 405,095
  • 59
  • 585
  • 614
spaceman12
  • 1,039
  • 11
  • 18

2 Answers2

1

You can use word-break or white-space property in the div:

http://caniuse.com/#feat=word-break
http://www.w3schools.com/cssref/playit.asp?filename=playcss_white-space&preval=pre-line

Ricardo Souza
  • 16,030
  • 6
  • 37
  • 69
0

Hopefuly these links will help you,

JavaScript: How to add line breaks to an HTML textarea?

http://www.sitepoint.com/forums/showthread.php?430599-lt-textarea-gt-new-line

just test for return character

Community
  • 1
  • 1
Lemex
  • 3,772
  • 14
  • 53
  • 87