title: JavaScript - Split Parent of Selection
body: <p>Using JavaScript (and potentially <a href="https://github.com/timdown/rangy" rel="nofollow noreferrer">Rangy</a>) I am trying to create a utility function that will allow me to "split" an element based on the selection and a selector that I pass in. For instance, let's say we had the following:</p>
  
  <pre><code>&lt;div class="designer" contenteditable="true"&gt;
      &lt;div class="content"&gt;
          &lt;p&gt;
              Here is &lt;span style="color: pink;"&gt;some cool&lt;/span&gt; stuff.
          &lt;p&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Now let's say the user had their cursor between "some" and "cool". I want to be able to call a function like this:</p>
  
  <pre><code>$splitParent('p'):
  </code></pre>
  
  <p>which would yield the following:</p>
  
  <pre><code>&lt;div class="designer" contenteditable="true"&gt;
      &lt;div class="content"&gt;
          &lt;p&gt;
              Here is &lt;span style="color: pink;"&gt;some&lt;/span&gt;
          &lt;p&gt;
          &lt;p&gt;
              &lt;span style="color: pink;"&gt; cool&lt;/span&gt; stuff.
          &lt;p&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>and similarly calling this:</p>
  
  <pre><code>$splitParent('.content');
  </code></pre>
  
  <p>would yield this:</p>
  
  <pre><code>&lt;div class="designer" contenteditable="true"&gt;
      &lt;div class="content"&gt;
          &lt;p&gt;
              Here is &lt;span style="color: pink;"&gt;some&lt;/span&gt;
          &lt;p&gt;
      &lt;/div&gt;
      &lt;div class="content"&gt;
          &lt;p&gt;
              &lt;span style="color: pink;"&gt; cool&lt;/span&gt; stuff.
          &lt;p&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I haven't been able to think of a straight-forward way of accomplishing this. Any ideas?</p>