I am trying to dynamically create and destroy TinyMCE editors like this . 1) It appears that if I put a break point and check for tinymce editors after creation , i.e after the first for loop - I dont see them in the Browser 2) Nor do I see them in tinymce.editors in console
Hence my destroy is not working . However after everything , I can see the editors . Because the second for loop won't get executed .
Question mainly is , is there something like function has to exit and then browser makes the DOM changes ? If so should I put a sleep ? I got this idea from What is the JavaScript version of sleep()? i.e Browser makes DOM changes after the function exists or something like that . Can anyone enligthen me ?
for (var i=0;i<10;i++)
{
//i=0;
divObj = document.createElement('div');
divObj.className = 'top_div';
divObj.id = 'top_div_' + i;
divObj.innerHTML = 'Tiny Editor';
var textareaObj = document.createElement('textarea');
textareaObj.className = 'simpleEdit';
textareaObj.id = 'nic_' + i;
textareaObj.style.cssText="width: 300px; height: 100px;";
divObj.appendChild(textareaObj);
document.body.appendChild(divObj);
tinyMCE.execCommand('mceAddControl', false, textareaObj.id);
}
editors = tinyMCE.editors.length;
for (var i=0;i<editors;i++)
{
tinyMCE.remove(tinyMCE.editors[0]);
}