I need a simple text editor on my site, just with the following options:
- ordered and unordered lists
- heading or bold characters
- horizontal rule
Is there any way to get the above by coding, inside an existing textarea tag
I tried with contentEditable div but there is a lot of problems there, for example return changes the format of preceding text and so on.
I need a simple text editor on my site, just with the following options:
- ordered and unordered lists
- heading or bold characters
- horizontal rule
Is there any way to get the above by coding, inside an existing textarea tag
I tried with contentEditable div but there is a lot of problems there, for example return changes the format of preceding text and so on.
javascript
html
text-editor
Share
Improve this question
asked Sep 6, 2018 at 7:33
user7461846user74618462
A content editable is the way to go, textarea element contains only plain text, it can't have HTML. When using a content editable div, or maybe rather <pre>, you've to capture some key hits, e.g. TAB and ENTER, and prevent the default action.
– Teemu
CommentedSep 6, 2018 at 7:38
If you want to stick with pure textarea, there are no formatting options available and you have to work with key** or input events only to create basically some basic kind of markup. But markup is the only way for textarea - heading won't be bigger or bolder, horizontal rule will be just dashes across the textarea, unordered list items will start with * or -, no clickable links etc. You can hardcode contentEditable to your needs, like change Enter key behavior. It's more work, but it's worth it.
– mikiqex
CommentedSep 6, 2018 at 7:44
Add a ment
|
2 Answers
2
Reset to default
8
You can use ckeditor, it's very simple and customizable