Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>.

In a normal scenario, I can just do $('#tableId tr').addClass('classname');

However, in this case I have the html inside this.parentNode. How can I add the classname to the <tr> here?

like image 530
user544079 Avatar asked Dec 31 '25 02:12

user544079


1 Answers

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).addClass("className")

This adds the class to the tr tag in the parentNode.

like image 164
Zeblimiski Avatar answered Jan 02 '26 16:01

Zeblimiski