Reputation: 1109
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!!!
Upvotes: 0
Views: 2486
Reputation: 3794
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
Upvotes: 0
Reputation: 16456
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
Upvotes: 1