I have function that creates textareas fields on the fly upon a click on a link

I want to convert these textareas into tinymce wysiwyg

here is the code

        $("body").delegate("a.add_tab","click",function(e){
               e.preventDefault();
                 var uniq = $(this).attr("uniqid");
               add_tab_ui($(this),uniq);
            }); 

            function add_tab_ui(elem,uniq){
              var content = "<div class='wrapTab'><label >Tab Title:<input type='text' name='tab-title-"+uniq+"' id='tab-title' value='' placeholder = 'Add Tab Title' />  </label><br/><br/>";
              content+= "<label>Tab Content: <textarea name='tab-content-"+uniq+"' class='tinymce_enabled' id='tab-content' ></textarea></label><br/><br/><a href='#' class='del_tab'>Delete Tab</a><br/><br/></div>"  
              $(content).appendTo(elem.parent()).parent().sortable({cursor:'move'});
                add_tmce();
            }


                function add_tmce(){
                 tinyMCE.init();
                 tinyMCE.execCommand("mceAddControl", false,'textarea#tab-content');
               }

The way I did does not work
what I am really looking for is a way to automatically replace every textarea with id "tab-content" into tinymce wysiwyg and that should happen ON THE FLY
Also note that I am working inside wordpress back end and I MUST use the javascript way to do it NOT the php way wp_editor() function which is built-in wordpress
Any thoughts are appreciated :)

found the solutions

It was like that

function add_tmce(){
      var i=1;
      jQuery('.tinymce_enabled').each(function(e)
          {
           var id = jQuery(this).attr('id');

             if (!id)
              {
                    id = 'customEditor-' + i++;
                    jQuery(this).attr('id',id);
               }

             tinyMCE.execCommand('mceAddControl', false, id);

          });
         }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.