Search code examples
onclicktinymce

TinyMCE not add the onClick event in the tag


I have a function that, when you click a button, the selected text inside the box TinyMCE is wrapped in a span tag.

This is done this way:
      var apolo = '<span id=\"' + tag + '_' + key + '\" class=\"apolo' + type + '\" onClick=\"myFunction(this.id)\">' + sel + '</span>';
      tinyMCE.activeEditor.execCommand('mceInsertContent', false, apolo);

The expected result is:
      <span id="org_2" class="apoloP" onClick="myFunction(this.id);">SELECTED TEXT</span>
However, the result I am getting is:
      <span id="org_2" class="apoloP">SELECTED TEXT</span>

The onClick event that calls my function, was simply ignored.

In version 3.5.8 is working, but I had to move to version 4.0b2 due to another bug that no one could solve (How to stop TinyMCE to delete the span tags?).
In the end, all I got was out of a bug to another.

Does anyone know how I do for TinyMCE not delete my text?


Solution

  • Check the setting valid_elements and have a closer look if onclick is added there as a valid attribute. I looks like this attribute gets stripped out because it is not registered as valid.