We would like to know, how to set an attribute for an element using prosemirror . Is there any code available to do the same thing mentioned above, using prosemirror.
If we set the attribute using JavaScript it will remove after refresh by schema extension . So we need to add or update an attribute value for an element created using schema .
I think it depends on what you’re trying to achieve exactly.
You can use a plugin to add node decorations or inline decorations. You can take a look at the examples on prosemirror’s website, especially this one, that adds a class to elements: ProseMirror lint example
Another solution would be to define a node with custom attributes and add the attributes to the DOM representation of the node. You can check this example: ProseMirror dino example
From my understanding, the second solution seems to be the one you’re looking for, since you will then be able to change attributes in a transaction (with tr.setNodeAttribute)