views:

1990

answers:

4

Do you know how to make a DIV editable with JavaScript (cross-browser) ?

Something similar to a rich textarea, but that uses an editable iframe. I need something similar for a DIV.
I don't want to use a replacement textbox.

A: 

I prefer the Dijit InlineEditBox

Kitson
Yes but I don't want a replacement textbox, I just want the DIV to be editable. Thank you.
Christian Toma
A: 
How about his:

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

openidsujoy
That's exactly what I don't want to do. Thanks.
Christian Toma
+6  A: 

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>
Christian Toma
does this really work in IE6? cool!
Sander Versluys
Yes my friend, it really does work in Internet Explorer 6 ! Here is more info on this subject and the risks of using it in older versions of Internet Explorer. http://stackoverflow.com/questions/491790/risk-of-usingcontenteditable-in-ieThank you.
Christian Toma
+1  A: 

One reason to use a div would be to get around a textarea's 64k limit. So simply showing/hiding a textarea would defeat the purpose...

matt