IE acting strange with Node.contains and Text nodes

Viewed 817

Document

<!DOCTYPE html>
<html>
    <body>
        <div id='something'>
            A text node.
        </div>
    </body>
</html>

Script

var parent = document.getElementById('something');
var child = parent.childNodes[0];
alert(parent.contains(child));

Results

  • Chrome 58 - true
  • Firefox 53 - true
  • Edge 38 - true
  • IE 11 - false

I would expect a Node to contain its own childNode. However, in IE 11, if that child is a Text node, this is apparently not the case.

IE has odd behavior with Node.contains and Text nodes. What is the justification, and why does it occur?

1 Answers
Related