Fire a function on Select Content in TinyMCE Visual Editor in WordPress
My actual requirement is, When I select some text in WordPress visual editor, and then my custom text is replace in place of that text. I can do this in HTML Editor of Wordpress, but not in Visual Editor, as it is an iframe.
Only one thing worked but not fulfills my requirement, when I wrote a anchor tag after body part, and then the following script alerts the selected text.
var selectedText = jQuery("#content_ifr").prop("contentWindow").getSelection().toString();
var linkText = "<a href='yourlink.html'>"+selectedText+"</a>";