Search code examples
htmlmathcontenteditable

Contenteditable math element?


I know that we can create contentEditable p, div, span, etc........

But how can I create a contentEditable math element, like:

<math contenteditable>
.....
</math>

Solution

  • The contenteditable attribute is part of HTML, so would not expect it to work on MathML tags, and tests suggests the same.

    When you use MathML within HTML, you can wrap a math element inside an HTML container that is editable, say <div contenteditable><math ...>...</math></div>. However, although this makes the text editable, it seems to be editable as text only. When you have, say, <mi>A</mi> and you edit in a browser by replacing the A by B, then it becomes just B in the document tree, a character with no markup (and therefore appearing in upright style, not italic).

    So basically the answer appears to be “no.”