KenAdamsTR
KenAdamsTR

Reputation: 145

Setting content of an element in tinymce textarea

I have a tinymce textarea (TinyMCE 3.5.11) that contains an element like

<span id="lastreplytimeee">...</span>

I need to access and change the content of this element using the span id as selector.

I have tried things like

tinyMCE.DOM.setHTML('lastreplytime', $input.val());

None worked.

Any suggestions?

this line is within .ready:

    $().ready(function() {   
    jQuery('.flexy_datepicker_input').datetimepicker({
    lang:'tr',
    format:'Y-m-d H:i:s',
    dayOfWeekStart:1,
    onChangeDateTime:function(dp,$input){
    document.getElementById("lastreplytimeee").innerHTML = $input.val();
    }
    });
    });

Upvotes: 0

Views: 1094

Answers (3)

cammas
cammas

Reputation: 11

1.Maybe try it,this code gets TinyMCE content and then replace some elements (TinyMCE 5)

tinymce.get('TinyMceID').setContent(
      tinymce.get('TinyMceID').getContent().replace(
        $(tinymce.get('TinyMceID').dom.doc.getElementById('lastreplytimeee')).get(0).outerHTML,
        `<span  id="lastreplytimeee">` + newValue + `</span>`)
        )

2.or use this

tinymce.get('TinyMceID').dom.setHTML("lastreplytimeee", "newValue");

Upvotes: 1

KenAdamsTR
KenAdamsTR

Reputation: 145

Found the solution, tinymce requires its dom utility to access and play with an element inside it, like:

tinyMCE.activeEditor.dom.setHTML(tinyMCE.activeEditor.dom.select('selector'), 'some inner html');

Upvotes: 0

bozzmob
bozzmob

Reputation: 12584

document.getElementById("id") gets the reference to that particular tag. .innerHTML is to say assign value or display values in the HTML at that particular div you are referring to above.

Try to use-

document.getElementById("lastreplytimeee").innerHTML = $input.val();

If you are using jQuery, try this-

$("#lastreplytimeee").html = $input.val();

Hope it helps :) Happy Coding!

Upvotes: 0

Related Questions