JavaScript element.contentEditable Property

You are Here:

JavaScript element.contentEditable Property

The element.contentEditable property gets or sets whether the content of an element is editable or not.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <p contenteditable="true">You can edit this paragraph</p> <button onclick="myFunction()">Click Me</button> <p id="point"></p> <script> var x = document.getElementById("point"); var elem = document.getElementsByTagName("p")[0]; function myFunction(){ x.innerHTML = elem.contentEditable; } </script> </body> </html>

Syntax

element.contentEditable

Return Values

The return values will be in string type, not boolean.

ValueExplanation
trueSpecifies that the element is contenteditable.
falseSpecifies that the element cannot be edited.
inheritSpecifies that the element inherits its parent's editable status.

More Examples

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <p contenteditable="true">Edit this paragraph</p> <button onclick="myFunction()">Disable Editing</button> <p id="point"></p> <script> var x = document.getElementById("point"); var btn = document.getElementsByTagName("button")[0]; var elem = document.getElementsByTagName("p")[0]; function myFunction(){ if(elem.contentEditable == "true"){ elem.contentEditable = "false"; btn.innerHTML = "Enable Editing"; } else{ elem.contentEditable = "true"; btn.innerHTML = "Disable Editing"; } } </script> </body> </html>

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author