How to select the last rowspan in a table?

phX

I have a table with some <td>s, and a couple of them have rowspan attribute. I'm trying to select the very last one in the table, neither last-child nor last-of-type works.

Here is a jsfiddle: https://jsfiddle.net/p2cjwvj5/

<table class='myTable' border='1'>
    <tr>
        <td rowspan='3'>HEADER</td>
    </tr>
    <tr>
        <td>something</td>
    </tr>
    <tr>
        <td>something</td>
    </tr>
    <tr>
        <td rowspan='3'>HEADER2</td>
    </tr>
    <tr>
        <td>something2</td>
    </tr>
    <tr>
        <td>something2</td>
    </tr>
</table>
.myTable [rowspan]:last-of-type {
    color: red;
}

I'm trying to to select the cell that contains "HEADER2".

Is this possible? I know I can work around it by tagging the last rowspan with another class, just wonder if there is a cleaner method. Thanks!

Stickers

You can wrap each group of <tr>s into a <tbody>, then select the last tbody by either using :last-of-type or :last-child would be fine.

.myTable tbody:last-of-type td[rowspan] {
  color: red;
}
<table class='myTable' border='1'>
  <tbody>
    <tr>
      <td rowspan='3'>HEADER</td>
    </tr>
    <tr>
      <td>something</td>
    </tr>
    <tr>
      <td>something</td>
    </tr>
  </tbody>
  <tbody>
    <tr>
      <td rowspan='3'>HEADER2</td>
    </tr>
    <tr>
      <td>something2</td>
    </tr>
    <tr>
      <td>something2</td>
    </tr>
  </tbody>
</table>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to parse table with rowspan and colspan

From Dev

Select first column of table having rowspan

From Dev

Select first column of table having rowspan

From Dev

How to select the last inserted row in a table?

From Dev

How to select last record by date in a joined table

From Dev

jQuery how to select td with rowspan attribute?

From Dev

How do I select rows that correspond to a rowspan?

From Dev

How to calculate the table row that has rowspan attribute

From Dev

Ruby prawn-table gem : How to select last row of a table?

From Dev

unable to select entire row if rowspan is applied in bootstrap table

From Dev

Table in a table with rowspan and colspan

From Dev

Laravel 4 and Eloquent ORM - How to select the last 5 rows of a table

From Dev

Cassandra cql: how to select the LAST n rows from a table

From Dev

jQuery - How to select last column of all rows in a table?

From Dev

how to select all table records except last 2?

From Dev

How to select the last table from a list of hive tables?

From Java

How to use dynamic table rowspan in vue.js?

From Dev

How to auto rowspan table when have column be same value name

From Dev

How to rotate text on table with two rowspan using bootstrap

From Dev

AngularJS repeat with table and rowspan

From Dev

Complex table rowspan and colspan

From Dev

Proper table alignment and rowspan

From Dev

Table Cells hover and rowspan

From Dev

Html table, rowspan issue

From Dev

Complex table rowspan and colspan

From Dev

Dynamic rowspan in a Table Coldfusion

From Dev

Table layout colspan rowspan

From Dev

Table border top for rowspan

From Dev

How not to select the last element

Related Related

HotTag

Archive