Question

I have a CKEditor plugin and want to check, if the element at the current cursor position has a parent element with a special attribute and value.

I know, that I can check the path with editor.elementsPath().contains('tagname') but I not only want to check for the tagname but also for an attribute and an attributes value like tagname[attribute=value]. But it looks like this spelling does not work with the contains()function.

Any idea how to achive this?

Was it helpful?

Solution

You can pass evaluator function as a parameter of editor.elementPath().contains():

editor.elementPath().contains( function( element ) {        
    if ( element.is( 'tagname' ) && element.getAttribute( 'attribute' ) == 'value' )
        return true;
} ); // -> element or null
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top