title: TinyMCE 4 node duplication issue when updating selected node using setNode()
body: <p>Using TinyMCE 4, I am trying to implement a button with a fairly straightforward functionality: For the selected (highlighted) node, I want to update its class by clicking that button.</p>
  
  <p>I am updating the node by using the <code>setNode()</code> function. The problem is that, instead of just updating the existing node as expected, I am also getting a duplicate node.</p>
  
  <p>For example, say I have this text in the tinyMCE body:</p>
  
  <pre><code>&lt;p&gt;This is a paragraph.&lt;/p&gt;
  </code></pre>
  
  <p>Expected result after highlighting the text and clicking "MyButton":</p>
  
  <pre><code>&lt;p class="updated"&gt;This is a paragraph.&lt;/p&gt;
  </code></pre>
  
  <p>What I am getting instead:</p>
  
  <pre><code>&lt;p class="updated"&gt;
      &lt;p class="updated"&gt;This is a paragraph.&lt;/p&gt;
  &lt;/p&gt;
  </code></pre>
  
  <p>So for some reason the node is being duplicated (or wrapped by the same node?) and I cannot understand why.</p>
  
  <p>Relevant code:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
  tinymce.init({
  
      //...
  
      setup: function(editor){
  
          editor.addButton('MyButton', {
              name: 'MyButton',
              text: 'MyButton',
              icon: false,
  
              onclick: function() {
                  var selectedNode = window.parent.tinyMCE.activeEditor.selection.getNode(), //get the selected node
                      updatedNode  = $(selectedNode).addClass('updated'); //perform desired modifications to it
                      updatedNode  = updatedNode.get(0); //return the javascript element
  
                  //update the node:
                  window.parent.tinyMCE.activeEditor.selection.setNode(updatedNode);
  
              }//end onclick
          });//end addButton
  
      }//end setup
  
  });//end tinymce.init
  
  &lt;/script&gt;
  </code></pre>
  
  <hr>
  
  <p><strong>EDIT:</strong> I finally found a workaround for this. Instead of creating a new node (<code>updatedContent</code>) and then using it to set the selected node content (<code>window.parent.tinyMCE.activeEditor.selection.setContent(updatedContent);</code>), one should directly update the selected node (<code>selectedNode</code>). Like so:</p>
  
  <pre><code>$(selectedNode).addClass('updated');
  </code></pre>