1

I have a div like this

 <div class="sectionContent" contenteditable>
       <div class="capabilities" name="capabilities" >Some things</div>
 </div>

So i want everytime user type something in this div like

-Responsible,allways on time,love teamwork
-Willing to learn new things.

I will have new line after user press enter button.Here is the result i want.So how can i achivce that with js or jquery

-Responsible,allways on time,love teamwork</br>
-Willing to learn new things.</br>

Thanks for help.Kind regard

  • Check out this answer: http://stackoverflow.com/questions/784539/how-do-i-replace-all-line-breaks-in-a-string-with-br-tags – fredrover Feb 10 '16 at 02:20
  • 1
    `contentediable` does this already by default. Not understanding what the problem is. See [this demo](https://jsfiddle.net/gakwc4ud/) – charlietfl Feb 10 '16 at 02:28
  • @charlietfl i'm use var capabilities = $('.capabilities').text(); to get the text in contentediable .But the result i get is [Here](http://prntscr.com/a19per) –  Feb 10 '16 at 02:32
  • use `html()` and you will have `
    ` in there already.
    – charlietfl Feb 10 '16 at 02:33
  • @charlietfl still not working [here](http://prntscr.com/a19qm5) is what i get when i use .html() –  Feb 10 '16 at 02:36
  • by the way, it's `
    ` or `
    ` ... not sure '` would do anything
    – Jaromanda X Feb 10 '16 at 02:36
  • ok...different results in different browsers. Chrome repeats the div and class and Firefox just adds `
    `. You will need to parse differences or use an html editor probably for consistent results
    – charlietfl Feb 10 '16 at 02:42
  • @charlietfl i tried in chrome when you press enter it creates a new div that is why he is getting that result – guradio Feb 10 '16 at 02:44
  • I have [this](http://prntscr.com/a19syi) js function to add new line but here it's the [result](http://prntscr.com/a19t62) i get –  Feb 10 '16 at 02:45
  • Suggest you use an inline html editor script. Then you are assured consistent results cross browser – charlietfl Feb 10 '16 at 02:46
  • Is there another way to do –  Feb 10 '16 at 02:51

0 Answers0