Search code examples
jquerycelladdclass

how to add class to cell using jquery


I try to class to cell but i got the erroe .please correct my code

TypeError: table.rows[rowscount].cells[0].addClass is not a function

table.rows[rowscount].cells[0].addClass("txtwidth");

Solution

  • .addClass() is a function provided by jQuery, so it needs to be called in the jQuery wrapper object instead you are trying to invoke it using a dom element reference

    It is a messy solution

    $(table.rows[rowscount].cells[0]).addClass("txtwidth");
    

    or

    $(table).find('tr:eq(' + rowscount+') td:first-child').addClass("txtwidth");