简体   繁体   English

使用jQuery将类添加到表行

[英]add class to a table row using jQuery

I am getting 我正进入(状态

this.parentNode = '<tr><td>One</td>' +
                  '<td>Two</td>' +
                  '<td>Three</td>' +
                  '</tr>';

Now, I need to add a class to the <tr> . 现在,我需要在<tr>添加一个类。

In a normal scenario, I can just do $('#tableId tr').addClass('classname'); 在正常情况下,我可以做$('#tableId tr').addClass('classname');

However, in this case I have the html inside this.parentNode. 但是,在这种情况下,我在this.parentNode中有html。 How can I add the classname to the <tr> here? 如何在此处将类名添加到<tr>

You can do 2 things: 你可以做两件事:

This, 这个,

this.parentNode = '<tr class="className"><td>One</td>' +
                  '<td>Two</td>' +
                  '<td>Three</td>' +
                  '</tr>';

Or this, 或这个,

Define the this.parentNode just like how you did, and then do this : 像你做的那样定义this.parentNode,然后执行以下操作:

    $(this.parentNode).addClass("className")

This adds the class to the tr tag in the parentNode. 这会将类添加到parentNode中的tr标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM