How to make an HTML <div> element editable cross-browser?

JavascriptHtmlCross BrowserContenteditable

Javascript Problem Overview


Do you know how to make a <div> editable with JavaScript? I'm looking for cross-browser solution.

Something similar to a rich text area, but that uses an editable <iframe>. I need something similar for a <div>.
I don't want to use a replacement textbox.

Javascript Solutions


Solution 1 - Javascript

I found out how.

You use the contentEditable property of the DOMElement, like so

<div onClick="this.contentEditable='true';">
    lorem ipsum dolor lorem ipsum dolorlorem ipsum dolor
</div>

Solution 2 - Javascript

You can do this in pure HTML

<div class="editable" contenteditable="true">
    Editable text...
</div>

Hope this helps!

Solution 3 - Javascript

Set contentEditable property of the element to "true":

element.contentEditable = "true";

See also:

Solution 4 - Javascript

How about his: 

Make a hidden "textArea" , and upon selecting(clicking or Hover) the div , hide the Div and Show the textArea .

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCristian TomaView Question on Stackoverflow
Solution 1 - JavascriptCristian TomaView Answer on Stackoverflow
Solution 2 - JavascriptAndré FigueiraView Answer on Stackoverflow
Solution 3 - JavascriptMichał PerłakowskiView Answer on Stackoverflow
Solution 4 - JavascriptPostoView Answer on Stackoverflow