<tbody> tag displays in chrome but not source

亡梦爱人 提交于 2021-02-05 08:08:11

问题


In doing some scraping work I keep encountering the <tbody> tag in the Chrome DevTools inspector, but it doesn't appear in the source. For what I hope are obvious reasons, I find this super confusing. What's going on here? (I should also add that the html on this page is pretty malformed).

For example, DevTools shows:

<table>
    <tbody>
        <tr valign="top">
            <td>...</td>

Page source shows:

<table border="0">
    <tr valign="top">
        <td>

回答1:


The start tag for <tbody> is optional. That is, you can leave it out, but it is automatically inserted by the browser whenever needed.

And it is needed, because the rules say you can't have a tr directly in a table. The only children of a table element can be caption, colgroup, thead, tbody and tfoot.
So, if the browser encounters a tr outside a tbody, it inserts a tbody which the tr will reside in.

For a more formal way of saying this, see http://www.w3.org/TR/html-markup/tbody.html

By the way, the very same happens with other start tags, like <body>. If you omit that, writin, say, a <h1> directly after the </head>, the browser will insert an implied <body> automatically.



来源:https://stackoverflow.com/questions/34024136/tbody-tag-displays-in-chrome-but-not-source

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!