当前位置: 动力学知识库 > 问答 > 编程问答 >

How to add class to tr using jquery?

问题描述:

I am trying to use jquery to add classes to tr .

I tried the various options belwo but didnt seem to work.. Any help would be appreciated. N

 //jQuery("div.flexigrid > table.flexme1 > tr").addClass("cal");

or

jQuery("div.flexigrid > table.flexme1 > tr").addClass("sev1");

or

jQuery(".erow").addClass("sev2");

or

jQuery(".flexigrid > tr").addClass("sev3");

or

jQuery(".flexigrid >tr").addClass("sev4");

or

jQuery(".flexigrid >tr").addClass("sev5");

none of teh above seem to work

I would like the tr to have the class="sev" added to it.

<div class="flexigrid">

..< some other divs>

... <some other divs>

---

<div class="bDiv" style="height: 200px;">

<table cellspacing="0" cellpadding="0" border="0" class="flexme1" >

<tbody>

<tr class="sev1">

<td align="left" abbr="InstanceDisplayName8">

<div style="text-align: left; width: 190px;">undefined</div>

</td>

<td align="right" abbr="severity" class="sorted">

<div style="text-align: right; width: 40px;">&nbsp;</div>

</td>

<td align="right" abbr="Impact">

<div style="text-align: right; width: 40px;">0</div>

</td>

<td align="right" abbr="occurrencecount">

<div style="text-align: right; width: 40px;">undefined</div>

</td>

<td align="left" abbr="NotificationID">

<div style="text-align: left; width: 100px;">Host</div>

</td>

<td align="left" abbr="Name">

<div style="text-align: left; width: 120px;">Down</div>

</td>

<td align="right">

<div style="text-align: right; width: 130px;">undefined</div>

</td>

</tr>

<tr class="erow" class="sev1">

<td align="left" abbr="InstanceDisplayName8">

<div style="text-align: left; width: 190px;">undefined</div>

</td>

<td align="right" abbr="severity" class="sorted">

<div style="text-align: right; width: 40px;">&nbsp;</div>

</td>

<td align="right" abbr="Impact">

<div style="text-align: right; width: 40px;">1</div>

</td>

<td align="right" abbr="occurrencecount">

<div style="text-align: right; width: 40px;">undefined</div>

</td>

<td align="left" abbr="NotificationID">

<div style="text-align: left; width: 100px;">Host</div>

</td>

<td align="left" abbr="Name">

<div style="text-align: left; width: 120px;">Down</div>

</td>

<td align="right">

<div style="text-align: right; width: 130px;">undefined</div>

</td>

</tr>

<tr class="sev3">

<td align="left" abbr="InstanceDisplayName8">

<div style="text-align: left; width: 190px;">undefined</div>

</td>

<td align="right" abbr="severity" class="sorted">

<div style="text-align: right; width: 40px;">&nbsp;</div>

</td>

<td align="right" abbr="Impact">

<div style="text-align: right; width: 40px;">0</div>

</td>

<td align="right" abbr="occurrencecount">

<div style="text-align: right; width: 40px;">undefined</div>

</td>

<td align="left" abbr="NotificationID">

<div style="text-align: left; width: 100px;">Host</div>

</td>

<td align="left" abbr="Name">

<div style="text-align: left; width: 120px;">Down</div>

</td>

<td align="right">

<div style="text-align: right; width: 130px;">undefined</div>

</td>

</tr>

<tr class="erow" >

<td align="left" abbr="InstanceDisplayName8">

<div style="text-align: left; width: 190px;">undefined</div>

</td>

<td align="right" abbr="severity" class="sorted">

<div style="text-align: right; width: 40px;">&nbsp;</div>

</td>

<td align="right" abbr="Impact">

<div style="text-align: right; width: 40px;">1</div>

</td>

<td align="right" abbr="occurrencecount">

<div style="text-align: right; width: 40px;">undefined</div>

</td>

<td align="left" abbr="NotificationID">

<div style="text-align: left; width: 100px;">Host</div>

</td>

<td align="left" abbr="Name">

<div style="text-align: left; width: 120px;">BM1M</div>

</td>

<td align="right">

<div style="text-align: right; width: 130px;">undefined</div>

</td>

</tr>

<tr >

<td align="left" abbr="InstanceDisplayName8">

<div style="text-align: left; width: 190px;">undefined</div>

</td>

<td align="right" abbr="severity" class="sorted">

<div style="text-align: right; width: 40px;">&nbsp;</div>

</td>

<td align="right" abbr="Impact">

<div style="text-align: right; width: 40px;">0</div>

</td>

<td align="right" abbr="occurrencecount">

<div style="text-align: right; width: 40px;">undefined</div>

</td>

<td align="left" abbr="NotificationID">

<div style="text-align: left; width: 100px;">Host</div>

</td>

<td align="left" abbr="Name">

<div style="text-align: left; width: 120px;">Down</div>

</td>

<td align="right">

<div style="text-align: right; width: 130px;">undefined</div>

</td>

</tr>

<tr class="erow" >

<td align="left" abbr="InstanceDisplayName8">

<div style="text-align: left; width: 190px;">undefined</div>

</td>

<td align="right" abbr="severity" class="sorted">

<div style="text-align: right; width: 40px;">&nbsp;</div>

</td>

<td align="right" abbr="Impact">

<div style="text-align: right; width: 40px;">4</div>

</td>

<td align="right" abbr="occurrencecount">

<div style="text-align: right; width: 40px;">undefined</div>

</td>

<td align="left" abbr="NotificationID">

<div style="text-align: left; width: 100px;">Host</div>

</td>

<td align="left" abbr="Name">

<div style="text-align: left; width: 120px;">BM1N</div>

</td>

<td align="right">

<div style="text-align: right; width: 130px;">undefined</div>

</td>

</tr>

<tr >

<td align="left" abbr="InstanceDisplayName8">

<div style="text-align: left; width: 190px;">undefined</div>

</td>

<td align="right" abbr="severity" class="sorted">

<div style="text-align: right; width: 40px;">&nbsp;</div>

</td>

<td align="right" abbr="Impact">

<div style="text-align: right; width: 40px;">0</div>

</td>

<td align="right" abbr="occurrencecount">

<div style="text-align: right; width: 40px;">undefined</div>

</td>

<td align="left" abbr="NotificationID">

<div style="text-align: left; width: 100px;">Host</div>

</td>

<td align="left" abbr="Name">

<div style="text-align: left; width: 120px;">Down</div>

</td>

<td align="right">

<div style="text-align: right; width: 130px;">undefined</div>

</td>

</tr>

<tr class="erow" >

<td align="left" abbr="InstanceDisplayName8">

<div style="text-align: left; width: 190px;">undefined</div>

</td>

<td align="right" abbr="severity" class="sorted">

<div style="text-align: right; width: 40px;">&nbsp;</div>

</td>

<td align="right" abbr="Impact">

<div style="text-align: right; width: 40px;">0</div>

</td>

<td align="right" abbr="occurrencecount">

<div style="text-align: right; width: 40px;">undefined</div>

</td>

<td align="left" abbr="NotificationID">

<div style="text-align: left; width: 100px;">Host</div>

</td>

<td align="left" abbr="Name">

<div style="text-align: left; width: 120px;">Down</div>

</td>

<td align="right">

<div style="text-align: right; width: 130px;">undefined</div>

</td>

</tr>

<tr >

<td align="left" abbr="InstanceDisplayName8">

<div style="text-align: left; width: 190px;">undefined</div>

</td>

<td align="right" abbr="severity" class="sorted">

<div style="text-align: right; width: 40px;">&nbsp;</div>

</td>

<td align="right" abbr="Impact">

<div style="text-align: right; width: 40px;">0</div>

</td>

<td align="right" abbr="occurrencecount">

<div style="text-align: right; width: 40px;">undefined</div>

</td>

<td align="left" abbr="NotificationID">

<div style="text-align: left; width: 100px;">Host</div>

</td>

<td align="left" abbr="Name">

<div style="text-align: left; width: 120px;">Down</div>

</td>

<td align="right">

<div style="text-align: right; width: 130px;">undefined</div>

</td>

</tr>

<tr class="erow" >

<td align="left" abbr="InstanceDisplayName8">

<div style="text-align: left; width: 190px;">undefined</div>

</td>

<td align="right" abbr="severity" class="sorted">

<div style="text-align: right; width: 40px;">&nbsp;</div>

</td>

<td align="right" abbr="Impact">

<div style="text-align: right; width: 40px;">0</div>

</td>

<td align="right" abbr="occurrencecount">

<div style="text-align: right; width: 40px;">undefined</div>

</td>

<td align="left" abbr="NotificationID">

<div style="text-align: left; width: 100px;">Host</div>

</td>

<td align="left" abbr="Name">

<div style="text-align: left; width: 120px;">Down</div>

</td>

<td align="right">

<div style="text-align: right; width: 130px;">undefined</div>

</td>

</tr>

</tbody>

</table>

<div class="iDiv" style="display: none;"></div>

</div>

</div><!-- end of flexidiv>

网友答案:

You don't have a div with the class flexigrid. You have div.bDiv

Second, there is an error on the table line:

class="flexme1 stype=&quot;display: none&quot;"

It should be:

class="flexme1" style="display: none"

Third, you have multiple elements with id="rowHost". Elements must have a unique ID.

网友答案:

first, no div in your code has the class "flexigrid" so jquery wont find what you want it to.

now, this should work

$("bDiv tr").addClass("sev1");
分享给朋友:
您可能感兴趣的文章:
随机阅读: