Zorro Here
Zorro Here

Reputation: 305

How to manipulate tinyMCE content using jQuery in WordPress?

For last two days I have been searching for a way to manipulate tinyMCE content using custom button in WordPress. Using editor.getBody(), I was able to get content and manipulate it easily but I don't know how to get cursor position or selected element. I tried getContent but that behaves differently.

What I am doing is this: when user clicks the custom button I need to find it's certain parent element and then manipulate it. Is there any way I can do that?

Upvotes: 2

Views: 211

Answers (1)

Thariama
Thariama

Reputation: 50832

Yes, this works. You can use the setup tinymce config parameter:

setup : function(ed) {

    ed.on('init', function(e){
        $(ed.getBody()).bind('change', function(e) {
            // do your magic here if e.target is your button!         

        });
    });
}

An other way to get the node of your caret in the editor is to call:

tinymce.get('your_editor_id').selection.getNode();

Upvotes: 1

Related Questions