No $(element).css() neither?


I know I should not alter document structure by other means than editor transactions. Now this is probably just lack of my deeper understanding, but does that also stands for css?

I’m trying to do a simple highlighting, which is highlighting something in the text based on mouseover. I have implemented it with marks and I’m removing and adding marks with different classes based on external events. Those classes have different styles.

But I’m really tempted to do something like

$(class assigned to marks).css({'background-color': 'red'});

It would simplify the code dramatically.

This actually works, but not if the mark spans across multiple nodes. For some reason only the span element over which the mouse is at a given time has background changed.

Any insight if this could be done or do I need to stay with adding/removing marks for highlighting?


Nope, that won’t work either. You’ll have to use ProseMirror decorations to do this kind of styling.

Thanks @marijn I was not familiar with Decorations. Will try to find some example and see how to use it.