14

There are several questions about asking how to make a div editable. However one could just use a textarea or input field and make those disabled or readonly. I would guess this would yield better semantics. Even the example given at MDN looks like a plain old input field to me.

So why would I use an editable div? What are its advantages over textareas and input fields?

I just had a look at an example I found in the tag wiki contenteditable.

Is the advantage, that I can use markup inside an editable div, but not inside a textarea or an input field? Wouldn't it then be more semantically correct to allow children to a textarea. Or introduce a whole new element like they did a lot with HTML5. Something like richtextarea?

Community
  • 1
  • 1
Angelo.Hannes
  • 1,729
  • 1
  • 18
  • 46
  • 3
    divs can have childs. – Eun Feb 06 '15 at 07:44
  • @Eun, People can have childs to. What is the point of your comment? Asker wrote that he know that. Nice research, and quite interesting question, +1 from me. – Jacek Kowalewski Feb 06 '15 at 08:11
  • 2
    This calls for opinions and speculations on why something was or was not done in specs, even though the question nominally starts with a question about the use of markup. It is also obscure—e.g., how would making an input field disabled or readonly help? Please consider posting a new question if you have a *practical, objectively answerable, constructive question about programming or markup*. – Jukka K. Korpela Feb 06 '15 at 08:46
  • The short answer is formatting. Consider a code editor with syntax highlighting, or any document with headings, subheadings, bold and italic text, for example. – Tim Down Feb 06 '15 at 09:23
  • When I first found out about `contentEditable`, I felt the same. But the fact is a `textarea` element cannot have an `img` in it. I think the _only_ reason to go for a `contentEditable` `div` would be if you want to allow [WYSIWYG](https://en.wikipedia.org/wiki/WYSIWYG) formatting and/or non-text content within the edit input field and it should not be the default/go-to when making multi-line input fields. – m-smith Apr 12 '17 at 13:40

1 Answers1

8

Your theorical "richtextarea" doesn't exist, so when people want to allow the users to write content including formatting, tables, images, etc... they must use what is available and that's an element with contentEditable.

Of course, if you look at a plain "contentEditable" element it will be boring, so you must look at a full featured editor like CKEditor or TinyMCE that provides a full interface built upon this feature.

AlfonsoML
  • 12,634
  • 2
  • 46
  • 53