FIX: innerText Property Gives Incorrect Result with contentEditable Property (811037)



The information in this article applies to:

  • Microsoft Internet Explorer (Programming) 5.5 SP2

SYMPTOMS

If the contentEditable attribute of a PRE tag on element is set to TRUE, the innerText property does not behave as expected. If you insert line breaks in the text that is inside the PRE tag and then use the innerText property to retrieve the text, you notice that it does not include the line breaks. You may experience this behavior with Microsoft Internet Explorer 5.5 Service Pack 2 when you install the security updates that come with the Microsoft Knowledge Base article 313675, or with later cumulative updates.

RESOLUTION

To resolve this problem, install the following security update for Microsoft Internet Explorer 5.5 Service Pack 2.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Paste the following code in Microsoft Notepad and then save it as Test.htm:
    <HTML>
    <SCRIPT type="text/javascript">
    function showText()
    {
      alert("!!" + document.getElementById("div1").innerText+ "!!");
    }
    </SCRIPT>
    <BODY>
    <DIV id="div1" name="div1" contentEditable="true">
    <PRE id='pre1'  style='margin:0px;'>
    Press enter anywhere in this text and press the button.
    </PRE>
    </DIV>
    <INPUT type="button" value="Button" id=button1 name=button1 onclick="showText()">
    </BODY></HTML>
  2. In Internet Explorer, locate Test.htm.
  3. Put the pointer in the middle of the text line and then press ENTER. The line breaks as expected. Click the button.
The result that you expect is for a message box to display the text as it appears in the browser with line breaks that break the text in two. However, after you install Internet Explorer 5.5 SP2 and patch Q313675, the message box displays the text in a single line without any line breaks.

Modification Type:MajorLast Reviewed:11/5/2003
Keywords:kbInetDev kbMSHTML kbDHTML kbfix KB811037 kbAudDeveloper