2

How can I display an alert with ckeditor if a button is pressed?

Here's the code:

$(document).ready(function () {
      $(".cke_button__bold").click(function () {
          editor.on("CKEDITOR.cke_button__bold",CKEDITOR.cke_button_on);

          function handleAfterCommandExec(evt){
                var commandName = CKEDITOR.command.cke_button__bold;
                // For 'bold' commmand
                if (commandName == 'cke_button__on')
                {
                    alert("Bold button pressed!");

                }
         }
     });
});
parchment
  • 4,063
  • 1
  • 19
  • 30

1 Answers1

4

event delegation

Event delegation allows us to attach a single event listener, to a parent element, that will fire for all descendants matching a selector, whether those descendants exist now or are added in the future.

$(document).ready(function () {
      $(document).on('click','.cke_button__bold',function () {
         if($(this).hasClass('cke_button_on'))//checking for enable only
         {
           alert("Click event occure when only enable");
         }
     });
});

Updated DEMO

Community
  • 1
  • 1
Manwal
  • 23,450
  • 12
  • 63
  • 93