Search code examples
javascriptckeditorwysiwyg

Get the parent tag for cursor position in CKEditor 4


This seems like something simple to do but I am unable to find the answer I need from the docs.

I have created a function which inserts blockquote/cite HTML, however I need to wrap this in an IF statement to detect whether it is already inside a blockquote element and not include the tag if so

What I am trying to do is get the parent tag of the current cursor position:

    exec : function( editor ){                          
        alert( editor.getParent() ); 
    }

Solution

  • If you want to check whether caret is already inside blockquote, then you should use:

    editor.elementPath().contains( 'blockquote' )
    

    This will look for blockquote element in the entire path - not only in the last node (which does not even have to be an element).

    See docs for CKEDITOR.dom.elementPath.