4

I thought I knew JavaScript pretty well, but then I thought about how rich text editors work, such as CKeditor, and realized I had no idea.

I assume the buttons are somehow hooked up via JavaScript to a text area, but how is it marked up.

Is there something special about rich text editors on the web, or is it just lots of fancy js?

CafeHey
  • 5,699
  • 19
  • 82
  • 145

3 Answers3

3

Lots of fancy.js, and what used to be an MS extension to the DOM called "contentEditable", which basically turns any dom element into a simple text editor. The JS is there to allow doing things like bold/italics/fonts/inserting other DOM elements (tables, images, etc...). but it all comes down to contentEditable in the end.

Marc B
  • 356,200
  • 43
  • 426
  • 500
2

You can do it with contentEditable propertiy of div element.. Let say you have bold button. User click it, then you call a js function and open a tag like <b> when user click normal button you close it .. Same it with color.. Open a <span style="backround-color:red"> .. It's basically you style div text with js.. Try jquery for easy dom manipulation.

Fatih Donmez
  • 4,319
  • 3
  • 33
  • 45