Search code examples
javascriptckeditor

How to access elements by class with CKEditor 4?


I am building a plugin for CK-Editor and having trouble accessing span elements by their class name.

I've added the javascript commands to the plugin, but they aren't working. And when I try the same in the browser console, I get an empty array returned.

The span looks like the following:

<span class="rk_section" name="gXVyh" tags="test">UNITED STATES</span>

... and I've also tried the following directly in the browser console:

document.getElementsByClassName('rk_section')

CKEDITOR.document.find('.rk_section')

Both return empty arrays.

I'm baffled why this isn't working.


Solution

  • For a CKEditor instance named editor1:

    CKEDITOR.instances.editor1.document.$.getElementsByClassName('rk_section')