Add class to a DataTable

6

I'm making changes to a pagina.aspx of a system, however many things are generated through language functions.

<table id="ctl19_tableAreas" style="height:100%;width:100%">
    <tbody>
        <tr style="height:249px;">
            <td style="width:33%;padding-top:20px;" valign="top">
            </td>

            <td style="width:33%;padding-top:20px;" valign="top">
            </td>

            <td style="width:33%;padding-top:20px;" valign="top">
            </td>
        </tr>
    </tbody>
</table>

So my question is how do I add a class in these columns:

style=width:33%;
padding-top:20px;
valign=top

It can not be for everyone because inside each one has other tables, a total confusion.

    
asked by anonymous 24.11.2015 / 05:58

2 answers

1

You can use the jQuery child selector

$("table#ctl19_tableAreas tr>td").addClass("myClass");
.myClass {
  width: 33%;
  padding-top: 20px;
  color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><tableid="ctl19_tableAreas" style="height:100%;width:100%">
  <tbody>
    <tr>
      <td>
        a
      </td>

      <td>
        b
      </td>

      <td>
        c
      </td>
    </tr>
  </tbody>
</table>
    
24.11.2015 / 16:34
1

You can use the > selector that indicates immediate descent. For example #ctl19_tableAreas td will select all td within that table with id ctl19_tableAreas but also tables within that table.

However using '#ctl19_tableAreas > tbody > tr > td' ensures that only td descendants of the first table are selected.

    
24.11.2015 / 19:21