Get element className



Is it possible get the classname from element where is cursor| located in editor content?

For clarification: (Click with mouse on element… Is highlighted. Same highlighting i need when you move cursor in editor with keyboard.)

Any way to solve this is much appreciate.

Thanks in advance.


You could use getTokenTypeAt and prefix the first word in the resulting string with cm- to get a class name (if it’s not empty).


thank you, but when try:

give me error:
Unable to get property ‘chunkSize’ of undefined or null reference / codemirror.js (405,37)

same error with:

Am I doing anything wrong?


Yes, you’re passing the wrong kind of arguments to getTokenAt. I linked the docs—take a look at them.


thank you!
It works