title: TinyMCE wrap element with another one (the new one)
body: <p>I am creating plugin for TinyMCE and I need to wrap existing elem (node) with new one.</p>
  
  <p>For example, if I have paragraph:</p>
  
  <pre><code>&lt;p&gt;hello&lt;/p&gt;
  </code></pre>
  
  <p>after command I need:</p>
  
  <pre><code>&lt;div id="someid"&gt;&lt;p&gt;hello&lt;/p&gt;&lt;/div&gt;
  </code></pre>
  
  <p>I tried below but it doesn;t wrap paragraphs, only theirs body, for example:</p>
  
  <pre><code>tinyMCEPopup.editor.execCommand('mceReplaceContent',true,'&lt;div id="someid"&gt;{$selection}&lt;/div&gt;')
  </code></pre>
  
  <p>creates:</p>
  
  <pre><code>&lt;p&gt;&lt;div id="someid"&gt;hello&lt;/div&gt;&lt;/p&gt;
  </code></pre>
  
  <p>What is the easiest way to do it?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>Finaly I decided to use below construction (no jQuery):</p>
  
  <pre><code>// Get instance of the editor       
  var ed = tinyMCEPopup.editor;
  
  // we are collecting &lt;p&gt; or other default tag to cover it       
  var node = tinyMCEPopup.editor.selection.getNode();
  
  // create new dom objects   
  var newNode =  ed.dom.create('div', {'class' : 'accordionContent'}); 
  var newHNode =  ed.dom.create('h2', {'class' : 'accordionTitle'},document.forms[0].title.value);
  
  // dom modifications
  ed.dom.add(node.parentNode, newHNode);
  ed.dom.add(node.parentNode, newNode);
  newNode.appendChild(node);
  </code></pre>