<p>FCKeditor has InsertHtml API (<a href="http://docs.fckeditor.net/FCKeditor_2.x/Developers_Guide/JavaScript_API" rel="nofollow noreferrer">JavaScript API document</a>) that inserts HTML in the current cursor position. How do I insert at the very end of the document?</p>

<p>Do I need to start browser sniffing with something like this</p>

<pre><code>if ( element.insertAdjacentHTML )    // IE 
    element.insertAdjacentHTML( 'beforeBegin',  html ) ; 
else                                // Gecko 
{ 
    var oRange = document.createRange() ; 
    oRange.setStartBefore( element ) ; 
    var oFragment = oRange.createContextualFragment( html ); 
    element.parentNode.insertBefore( oFragment,  element ) ; 
} 
</code></pre>

<p>or is there a blessed way that I missed?</p>

<p>Edit: Of course, I can rewrite the whole HTML, as answers suggest, but I cannot believe that is the "blessed" way. That means that the browser should destroy whatever it has and re-parse the document from scratch. That cannot be good. For example, I expect that to break the undo stack.</p>

[{'answer_id': 25291, 'author': 'Ryan Doherty', 'author_id': 956, 'author_profile': 'https://Stackoverflow.com/users/956', 'pm_score': 2, 'selected': False, 'text': '<p>It looks like you could use a combination of GetHTML and SetHTML to get the current contents, append your html and reinsert everything into the editor. Although it does say </p>\n\n<blockquote>\n  <p>Note that when using this method, you will lose any listener that you may have previously registered on the editor.EditorDocument.</p>\n</blockquote>\n\n<p>Hope that helps!</p>\n'}, {'answer_id': 720544, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<pre><code>var oEditor = FCKeditorAPI.GetInstance(\'Editor_instance\') ;\n    OldText=oEditor.GetXHTML( true );\n\n    oEditor.SetData( OldText+"Your text");\n</code></pre>\n'}, {'answer_id': 5564221, 'author': 'francois saab', 'author_id': 694541, 'author_profile': 'https://Stackoverflow.com/users/694541', 'pm_score': 1, 'selected': False, 'text': "<p>replace the buggy line <code>:element.insertAdjacentHTML('beforeBegin', html);</code></p>\n\n<p>with this jquery code:</p>\n\n<pre><code>try {\n      $(html).insertBefore($(element));\n      // element.insertAdjacentHTML('beforeBegin', html);\n\n} catch (err) { }\n</code></pre>\n"}]
['https://Stackoverflow.com/questions/25240', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2515/']