Reputation: 61
I am creating a new project which needs a simple html editor. How can I create simple text editor using jquery?
Upvotes: 6
Views: 47995
Reputation: 2905
I was looking for perfect answer. But didn't found any of them. At last went through basics.
Here's how i did it.
HTML:
<div id="editor" contenteditable="true">Lorem Ipsum is simply dummy text</div>
<button id="make-bold">Make bold</button>
JS:
document.getElementById('make-bold').addEventListener('click', function(event){
event.preventDefault();
var selection = window.getSelection();
var range = selection.getRangeAt(0).cloneRange();
var tag = document.createElement('strong');
range.surroundContents(tag);
selection.addRange(range);
});
Live demo - https://jsfiddle.net/im4aLL/Lyusxq3p/
I pullout the basic idea by this and finally made something which i use in my future projects.
I made EasyEditor - https://github.com/im4aLL/easyeditor from above concept. There are lot more things to do. Like when are wrapping a node you need to check wheather that selection already wrapped with other node or same node. Also there are lot of functions you need to overcome.
Or you may try my lightweight plugin which i made for guys like you who need full flexible solution to integrate it with another application.
http://habibhadi.com/lab/easyeditor/default-example.html
Upvotes: 4
Reputation: 12183
I forked the jQueryTE plugin (a great, minimal rich text editor) and made it jQuery Mobile compatible - it now resizes with the browser, and the panel will span 2 lines if necessary (portrait-view on iPhone for instance).
https://github.com/jeffijoe/jQuery-TE
A screenie of what this looks like:
Upvotes: 7
Reputation: 4683
By a simple search you can find a lot of editors so I recommend this one 10 jQuery Text Editor Plugins
Upvotes: 1
Reputation: 30688
for it you can directly download code of text editor and out it in your application you can download it from following sites:
http://www.intrepidstudios.com/projects/jquery-rich-text-editor/demo.aspx http://freshcode.co/plugins/jquery.contenteditable/demo.html
Upvotes: 2
Reputation: 2659
You may choose one of these: http://www.queness.com/post/212/10-jquery-and-non-jquery-javascript-rich-text-editors
I personally prefer TinyMCE, non jquery editor.
Upvotes: 0