Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML DOM contentEditable property

HTML DOM contentEditable property

HTML Element Object Reference Element object

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.
 可能值:     
  • inherit - Default. If the parent element is editable, the child element's content is also editable.
  • true - content is editable
  • false - content is not 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


    HTML Element Object Reference Element object