How to add className to specified text and bind a click event?

As the title suggests, I’m trying to get the corresponding text from the DOM and replace it, adding the className and click event I need, but it seems to be forcibly reset? Is there another way to achieve this?

The DOM in the editor is controlled by the library, because it needs to be able to draw and update the document, so you cannot just mutate it. See the decoration example for information on how to add attributes around content. Don’t put event handlers directly on nodes, just use an editor-wide handler and check the event target.