<table><tr><td>1</td></tr><tr><td>2</td></tr></table>
The above is a simple HTML code, and such a table is used in the work.
<table><tr><th>1</th></tr><tbody></tbody></table>
I want to use jquery to dynamically operate tbody HTML ();
Then I wrote the following code:
1 var html = "<tr> <TD> I am tbody </TD> </tr>"; 2 3 $ ("Table tbody" ).html (HTML );
Then I found the page changed
<Table> <tr> <TD> I am tbody </TD> </tr> <tbody> </table>
After some tests, we found that using js to get the tbody of a table and using the child element tbody of the table may not necessarily get the expected results.
Because the table tag has a tbody by default. The tbody is all the tr values in the table.
So when we do not write tbody or thead In the table
$ ("Table tbody") is equivalent to $ ("table ");
If we write only the tbody tag in the table and do not include all the tr tags, $ ("Table tbody") returns the opposite result, that is, the above Code will exclude the content in the self-declared tbody and obtain the content outside the tbody in the table.
Okay! Simple question. The solution is also simple:
<table><thead><tr><th>head</th></tr></thead><tbody><tr><td>body</td></tr></tbody></table>
Do not be lazy. Write the entire thead tbody in a standard way and there will be no problems @@