0

As I'm working on a <table> displayed on a page (still in Draft) on WordPress, something weird happened :

While I've written this very simple code on my editor :

<table>
  <tr scope="row"><th>Title</th><td>Some data</td></tr>
  <tr scope="row"><th>Title</th><td>Some data</td></tr>
</table>

…some extra code appeared while I'm inspecting it (actually the <tbody> element) :

<table>
  <tbody>
    <tr scope="row"><th>Title</th><td>Some data</td></tr>
    <tr scope="row"><th>Title</th><td>Some data</td></tr>
  </tbody>
</table>

I'm not using Gutenberg for managing this table. It's a pure html table displayed on a handmade template.

I can see this extra chunk of code when I use the Chrome DevTools inspector. And it doesn't appears on the website source code.

I can't figure out how this is happening. What am I missing here ?

1 Answer 1

0

As I'm working on a displayed on a page (still in Draft) on WordPress, something weird happened :

Nothing about this is weird or unexpected, but it would be if you were unaware of the DOM.

While I've written this very simple code on my editor :

This is raw HTML text sent from your server.

…some extra code appeared while I'm inspecting it (actually the element) :

Incorrect, this is not your HTML that you wrote on the server, this is the DOM, converted back into HTML text for your benefit in the user interface. The browser does not hold a HTML text chunk in memory, it parses and processes it first.

What's going on?

What you see in the browser dev tools is not the raw HTML the server sent, or even the HTML that's being rendered, it's a representation of the DOM, the document object model.

Your browser has taken that raw HTML and turned it into a tree of nodes, filling in gaps along the way. E.g. all webpages have a html and body node, and if you don't use a <body> or <html> tag in the raw source code the browser inserts one automatically.

Likewise all tables have a table body, wether you write the tag or not, the browser will assume everything inside <table> is the table body if you don't explicitly include it to try and be helpful, and because it's rare that a HTML document passes validation and is perfectly written.

Browsers are forgiving, and what you see on the page is the visual representation of a processed and parsed HTML document, turned into objects/nodes. The HTML you see in the browser dev tools is new HTML generated from that DOM tree it held in memory.

Take a look directly at the raw HTML source code sent by your server and you'll see there is no <tbody> tag, but even if there was it's still standard HTML that's been there in the spec for decades. Also take a look at table headers ( aka <thead> )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.