HTML DOM contentEditable property
Example
Settings
Element content is editable:
document.getElementById("myP").contentEditable = true;
Try it »
Definition and usage
The contentEditable property sets or returns whether the content of an element is editable.
Tip: You can also use the isContentEditable Use the property to check whether the element's content is editable.
Browser support
The numbers in the table indicate the version number of the first browser that supports this property.
| property | |||||
|---|---|---|---|---|---|
| contentEditable | 11.0 | 5.5 | 3.0 | 3.2 | 10.6 |
Syntax
Return the contentEditable property:
HTMLElementObject
.contentEditable
Set the contentEditable property:
HTMLElementObject
.contentEditable=true|false
Attribute values
| Value | Description |
|---|---|
| true|false | Describes whether the element's content is editable. |
可能值:
Technical Details
| Return value: | Boolean value, returns true if the element is editable, otherwise returns false |
|---|
More examples
Example
Check
Whether the element is editable:
var x = document.getElementById("myP").contentEditable;
x The output result is:
true
Try it »
Example
switch
The editing state of the element:
var x = document.getElementById("myP");
if (x.contentEditable == "true") {
x.contentEditable = "false";
button.innerHTML = "p element content is editable!";
} else {
x.contentEditable = "true";
button.innerHTML = "p element content is not editable!";
}
Try it »
Related pages
HTML Reference Manual: HTML contenteditable attribute
Element object