我是javascript / jquery的新手。 我有一个具有索引列(0,1,2,3等)的表。 我想使用javascript删除表的那一部分。 我尝试使用after()和replaceWith(),但无法真正做到正确。
css类是.jobStats。 我想在下面的代码中只删除th标签的内容。
<tr> <th>0 </th> <td> 2015-06-02</td> <td> ARCA</td> <td> FAILED</td> <td>2015-06-03 10:30:51.573000</td> <td> NaT</td> <td> NaT</td> <td> NaN</td> <td> NaN</td> <td> NaN</td> <td> 8704</td> <td> 223226518</td> <td> NaN</td> <td> NaN</td> </tr>有关如何实现这一点的任何想法?
提前致谢!
I am new to javascript/jquery. I have a table that has an index column (0,1,2,3 etc). I would like to delete that part of the table using javascript. I tried to use after() and replaceWith() but couldn't really get it right.
The css class is .jobStats. I would like to ONLY remove contents of th tag in the code below.
<tr> <th>0 </th> <td> 2015-06-02</td> <td> ARCA</td> <td> FAILED</td> <td>2015-06-03 10:30:51.573000</td> <td> NaT</td> <td> NaT</td> <td> NaN</td> <td> NaN</td> <td> NaN</td> <td> 8704</td> <td> 223226518</td> <td> NaN</td> <td> NaN</td> </tr>Any thoughts on how I can achieve that?
Thanks in advance!
最满意答案
只需使用remove()
$('.jobStats').remove();如果你想保留.jobStats并想要删除它的子.jobStats ,请使用empty()
$('.jobStats').empty();更新
$('th').empty();我只想删除表中th标签的内容。
将删除儿童和文本
此方法不仅删除子(和其他后代)元素,还删除任何文本
Just use remove()
$('.jobStats').remove();If you wish to keep .jobStats and want to remove its children, use empty()
$('.jobStats').empty();Update
$('th').empty();I only want to remove the contents of the th tag in the table.
will remove both children and text
This method removes not only child (and other descendant) elements, but also any text
更多推荐
发布评论