How to get static HTML source code via JavaScript?

When developing a tool (which I do not consider here as an important detail, to the question, given that I was able to develop MCVE below), I noticed that, at least in the versions of Chrome and Firefox that I have on my desktop, the line that I get from the attribute innerHTMLis not equal to the original source code that I wrote statically in the HTML file.

console.log(document.querySelector("div").innerHTML);
/*
  <table>
    <tbody><tr>
      <td>Hello</td>
      <td>World</td>
    </tr>
  </tbody></table>
*/
<div>
  <table>
    <tr>
      <td>Hello</td>
      <td>World</td>
    </tr>
  </table>
</div>
Run codeHide result

, <tbody> ( , HTML-!) , -, - page onload. .

, , , .

console.log(document.querySelector("div").innerHTML);
/*
  Hello
  World
*/
<div>
  <td>Hello</td>
  <td>World</td>
</div>
Hide result

, , "" (, <td> a <div>). , , , innerHTML HTML, : , HTML- <div>?

, , , , : D

+4
2

HTML DOM ( ). , , , DOM.

, , JavaScript. , innerHTML , HTML, DOM. JavaScript.

, , . . , AJAX .

, , "" HTML- . , JavaScript, script, , HTML.

+4

- . , , . JavaScript, - :

<div>
    <div class="td">Hello</div>
    <div class="td">World</div>
</div>

javascript, div.td td. .

+1

All Articles