title: Why is ContentEditable removing “ID” from div
body: <p>I am having problems with getting a HTML editor working.  We are using “contentEditable” to implement it, however when any paragraph formatting option is done without contents selected, IE removes the ID from one of the divs in the page.</p>
  
  <p>The problem repeats for me with the HTML, </p>
  
  <ol>
  <li>just save it to a file,  </li>
  <li>then open it in IE</li>
  <li>enable jscript when asked </li>
  <li>push the button</li>
  <li>check you get two message boxes
  
  <ol start="2">
  <li>first one says “MainContents = object”</li>
  <li>second one says “MainContents = NULL”</li>
  </ol></li>
  </ol>
  
  <p>I am using IE 6.0.2900.5512 with XP SP3</p>
  
  <p><strong>So does this repeat for you?</strong></p>
  
  <p><strong>What is going on?</strong></p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  
  &lt;/head&gt;
  
  &lt;body id="BODY"&gt;
  &lt;div contentEditable="true" id="EDITBOX"&gt; 
  &lt;/div&gt;
  
  &lt;div id="MAINCONTENTS" unselectable="on"&gt;
  &lt;button title="Ordered List" unselectable="on"
      onclick='alert("MainContents = " + document.getElementById("MAINCONTENTS")); 
      document.execCommand("InsertOrderedList");
      alert("MainContents = " + document.getElementById("MAINCONTENTS"));
                       '&gt;
      Push Me
  &lt;/button&gt;
  &lt;/div&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  
  &lt;script type="text/javascript"&gt;
      document.getElementById("EDITBOX").focus();
  &lt;/script&gt;
  </code></pre>
  
  <hr>
  
  <p><strong>Background</strong>
  I work for an ISV that sell software to corporations, at present all our customers use IE and there is no market depend to support other browsers.  I have been told to implement an HTML editor using contentEditable.   All the formatting options are based on document.execCommand(), e.g. document.execCommand(“bold”);</p>
  
  <p>Due to licensing restrictions (LGPL is not liked) and/or cost it is very hard to get approval to use a 3rd party HTML editor.  It took us a log time just to be allowed to use jquery.</p>
  
  <p>I have the editor working apart from the case of paragraph formatting commands when the user does not have any items selected.  The HTML I posted is a small bit of HTML I wrote to reproduce the problem I am having.</p>
  
  <p>see also <a href="http://www.maconstateit.net/tutorials/JSDHTML/JSDHTML12/jsdhtml12-02.htm" rel="nofollow noreferrer">http://www.maconstateit.net/tutorials/JSDHTML/JSDHTML12/jsdhtml12-02.htm</a> and 
  <a href="https://stackoverflow.com/questions/491790/risk-of-using-contenteditable-in-ie">Risk of using contentEditable in IE</a></p>