How to override ckeditor button action

In this article we will see how we can override ckeditor button.

How to override ckeditor button

CKEDITOR.on('instanceReady', function (ev) {
   // Create a new command with the desired exec function
   var editor = ev.editor;
   var overridecmd = new CKEDITOR.command(editor, {
   exec: function (editor) {
        //place your custom button code here
        }
   });

   // Replace the old button's exec function with the new one
   ev.editor.commands.buttonName.exec = overridecmd.exec;
   //buttonName = name of the button you want to override
});

CKEDITOR.replace('editorInstance'); //editorInstance = the id of the ckeditor whose button is been modified.