code: function( containerNode, html )
      {
          var sel = window.getSelection();
          if( sel.getRangeAt && sel.rangeCount )
          {
              var range = sel.getRangeAt(0);
              // Range.createContextualFragment() would be useful here but is
              // only relatively recently standardized and is not supported in
              // some browsers (IE9, for one)
              var el = document.createElement('div');
              el.innerHTML = html;
              var frag = document.createDocumentFragment(), node, lastNode;
              while ( (node = el.firstChild) ) {
                  lastNode = frag.appendChild(node);
              }
              if( isOrContainsNode(containerNode, range.commonAncestorContainer) )
              {
                  range.deleteContents();
                  range.insertNode(frag);
              }
              else {
                  containerNode.appendChild(frag);
              }
              // Preserve the selection
              if( lastNode )
              {
                  range = range.cloneRange();
                  range.setStartAfter(lastNode);
                  range.collapse(true);
                  sel.removeAllRanges();
                  sel.addRange(range);
              }
          }
      }
docs: http://stackoverflow.com/questions/6690752/insert-html-at-caret-in-a-contenteditable-div/6691294#6691294 http://stackoverflow.com/questions/4823691/insert-an-html-element-in-a-contenteditable-element http://stackoverflow.com/questions/6139107/programatically-select-text-in-a-contenteditable-html-element