IE8: the option tag gets the default attribute "selected" (And cloneNode makes a mess)

IE seems to automatically add the "selected" attribute in the option tag.
But then if you clone a Node, everything gets weird.

If you open the page in IE8 using the code below:

<html>
<body>
  <form><select><option>o1</option></select></form>
  <script>

      // without clone node
      var elm = document.getElementsByTagName('form')[0];
      alert(elm.innerHTML);

      // using the form as the root to clone
      elm = document.getElementsByTagName('form')[0].cloneNode(true);
      alert(elm.innerHTML);

      // using the select as the root to clone
      elm = document.getElementsByTagName('select')[0].cloneNode(true)
      alert(elm.innerHTML);

  </script>
</body>
</html>

You'll get:

The first warning, with a miserable "selected" attribute in the option tag.
The second warning, without an attribute in the option tag (this is normal, as in any other browser!)
The third notification with the repeated appearance of "selected"

Any idea why this attribute appears?
And why does cloneNode seem to accidentally delete it or not?

. , ?
, JS PURE
: -\

+3
1

, select. , , IE . node, , dom, . , .

0

Source: https://habr.com/ru/post/1716567/


All Articles