Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between document.body.contentEditable='true'; and document.designMode='on';

Tags:

javascript

It seems both allow you to edit the document, so what's the difference?

like image 533
Randomblue Avatar asked Oct 31 '11 08:10

Randomblue


People also ask

What is Contenteditable?

The contenteditable attribute specifies whether the content of an element is editable or not. Note: When the contenteditable attribute is not set on an element, the element will inherit it from its parent.

How do I use designMode in documents?

The Design Mode is a browser specific property that allows us to directly edit the document ( website's text contents ), by default this property is set to the off state. To enable this mode open the developer console for your browser, and then type document. designMode="on" .

How do you use Contenteditable in Javascript?

You can add the contenteditable="true" HTML attribute to the element (a <div> for example) that you want to be editable. If you're anticipating a user to only update a word or two within a paragraph, then you could make a <p> itself editable.


1 Answers

In this case, they're equivalent. contentEditable makes the element it's applied to and all descendant nodes editable. designMode makes the entire document editable.

There's a great summary of the history of both properties available on the WHATWG blog — The Road to HTML 5: contentEditable. It's worth a read, if you're interested.

like image 93
Andy E Avatar answered Nov 11 '22 05:11

Andy E