John Kim
John Kim

Reputation: 1872

Getting HTML value from Tinymce

Is there a way to get HTML contents from TinyMCE editor using jQuery so I can copy this over to another div?

I tried several methods like val() on content but it doesn't seem to be working...

Upvotes: 4

Views: 10779

Answers (6)

MikeRyz
MikeRyz

Reputation: 289

I was trying charlietfl method: $(selector).tinyMCE().getContent();

There was an error:

[$(selector).tinyMCE().getContent();][1]

This way with activeEditor worked for me:

activeEditor

tinymce.activeEditor.getContent()

Source

Here is my code:

$(document).ready(function() {

    $(document).on("click", ".btnClassClose", function () {

        var tinyMCEcontent = tinymce.activeEditor.getContent();

        var getAttrIDArray = [];


        $("#" + getelementId).html("");
        $("#" + getelementId).html(tinyMCEcontent);
        $("#" + getelementId).append(buttonEDI);

 
        var PageName = new Object();
        PageName["mdlPageId"] = getelementId;
        getAttrIDArray.push(PageName);

        var PageName = new Object();
        PageName["mdlPageContentHtml"] = tinyMCEcontent;
        getAttrIDArray.push(PageName);


        var PageName = new Object();
        PageName["mdlPageName"] = "Default";
        getAttrIDArray.push(PageName);

        var PageName = new Object();
        PageName["mdlAligen"] = "Central";
        getAttrIDArray.push(PageName);

        var PageName = new Object();
        PageName["mdlOrderNumberHorizontal"] = "1";
        getAttrIDArray.push(PageName);


        alert(JSON.stringify(getAttrIDArray));


        var contentGetAttrIDArray = SecondMainSendAjax("CMS?handler=Content", getAttrIDArray);
      
    });
});

Upvotes: 0

odiszapc
odiszapc

Reputation: 4109

Using jQuery:

<textarea id="content" name="content">
$('#content').html()

Using TinyMce API:

$('#content').tinymce().activeEditor.getContent() // overall html
$('#content').tinymce().activeEditor.getContent({format : 'text'}) // overall text
$('#content').tinymce().selection.getContent() // selected html
$('#content').tinymce().selection.getContent({format : 'text'})) // selected text

Upvotes: 4

charlietfl
charlietfl

Reputation: 171669

if you are initilizing with jquery adaptor

 $(selector).tinyMCE().getContent();

Upvotes: 5

chrisvillanueva
chrisvillanueva

Reputation: 1359

if you are using tinymce, i would use it's internal methods to get the content you need. when i need to get content within the active editor, i do this:

var rawString = tinyMCE.activeEditor.getContent();

i invoke that method within an event handler function.

here is the documentation:

tinymce api

Upvotes: 3

Moin Zaman
Moin Zaman

Reputation: 25445

use TinyMCE's API to get it:

alert(tinyMCE.activeEditor.getContent());

Upvotes: 1

Ryan Brodie
Ryan Brodie

Reputation: 6620

Use text(); instead of val();.

Upvotes: 0

Related Questions