A
A
Akaero2018-02-14 21:51:28
JavaScript
Akaero, 2018-02-14 21:51:28

Does document.body.children[0].innerHTML work correctly?

Hello.
There is a code:

<html>
<head>
  <meta charset="utf-8">
</head>
<body>
 <div>Пользователи:</div>
  <ul>
    <li>Маша</li>
    <li>Вовочка</li>
  </ul>
  <!-- комментарий -->
</body>
</html>

All my life I thought that it would return Users:, and this line is returned by the code Indexes start from zero, sort of. What don't I know? link to sandbox
var elem = document.body.children[0].innerHTML;

var elem = document.body.children[1].innerHTML;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg, 2018-02-14
@Akaero

What do you mean? https://jsfiddle.net/thwjbt2n/1/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question