Range.toString() returns different result than `textContent` for `<pre>` nodes

Confirmed Issue #10291116 • Assigned to Kris K.

Details

Author
Robert K.
Created
Dec 21, 2016
Privacy
This issue is public.
Reports
Reported by 1 person

Sign in to watch or report this issue.

Steps to reproduce

Range.toString() treats new lines differently in <pre> elements than Node.textContent does.

This code produces the same result for both methods in Chrome/Firefox but different results in Edge. If the element type is changed to a <span> the behavior difference disappears.

Original bug report: https://github.com/tilgovi/dom-anchor-text-position/issues/4

<html>
<body>
  <pre id="content">
    One
    Two
    Three
  </pre>
  <script>
    var preEl = document.getElementById('content');
    console.log('Text content length', preEl.textContent.length);

    var range = document.createRange();
    range.setStart(preEl, 0);
    range.setEnd(preEl,preEl.childNodes.length);
    console.log('Range content length', range.toString().length);
  </script>
  </body>
</html>

Expected output
Text content length - 28
Range content length - 28

Actual output
Text content length - 28
Range content length - 31

Attachments

0 attachments

    Comments and activity

    • Microsoft Edge 38.14393.0.0, Microsoft EdgeHTML 14.14393, Windows 10.

    • Microsoft Edge Team

      Changed Assigned To to “Ibrahim O.”

    • Thank you for the feedback. We will look into that.

      Best regards,
      The MS Edge Team

    • Microsoft Edge Team

      Changed Assigned To to “Travis L.”

      Changed Status to “Confirmed”

      Changed Assigned To from “Travis L.” to “Kris K.”

    You need to sign in to your Microsoft account to add a comment.

    Sign in