A good place to start if you want to learn how richtext web editors work is to look into the contenteditable
attribute and the document.execCommand
method (the best editors use a lot more than this, but these are at the foundation). Over-simplified, an editor consists of a contenteditable
block and ways to invoke document.execCommand
on the text selection.
But, speaking as a person who has actually developed an editor of this kind, you might be better off using an existing one (CKEditor being a great one, in my opinion).
Edit: Note that contenteditable
is a proprietary (Microsoft) property, but most (all?) browsers have implemented it now, and it will be in HTML5.
Edit 2: I want to try to clear up a few misconceptions.
A div
or iframe
isn't in itself editable, it requires the contenteditable
attribute. The use of an iframe
is typically a workaround for the fact that older Gecko browsers only supported an alternative editable property (designMode
) that could only be applied to a whole document.
While some operations of advanced editors probably do employ innerHtml
, this isn't the key to making an editor on the web.