我的HTML页面有2个表:
class='af_column_column-header-table' and
id ='Table1'`。css:
.af_column_column-header-table {
width = 100% !important;
}
问题:
我只想在第一个表中这样做。
PS:我的页面上有很多使用相同样式类的表
af_column_column-header-table
。
答案 0 :(得分:1)
您可以在querySelectorAll
的帮助下使用:first-child
选择第一个表格,然后使用.style.width
设置样式:
var rows_count = document.querySelectorAll('table.af_column_column-header-table:first-child tr').length;
if( rows_count > 1){
document.getElementById('Table1').style.width = '99.3%';
}
我的页面上有很多表,它们使用相同的样式类af_column_column-header-table,我只想对第一个表执行此操作。
使用:first-child
选择器将达到目的。