I have a table view

<table> <tr> <th>...</th> <th>...</th> <th>...</th> </tr> <tr> <td>...</td> <td>...</td> <td>...</td> </tr> <tr> <td>...</td> <td>...</td> <td>...</td> </tr> </table> 

I need to add text to each cell of the column by clicking on the column header.

Stopped at this:

 $('document').ready(function (){ $('th').click(function(){ // А что дальше? }); }); 

    2 answers 2

     $('document').ready(function (){ $('#yourtable_id th').click(function(){ var th_num = $(this).index(); $('#yourtable_id tr').each(function(){ $(this).children('td').each(function(td_num){ if(td_num==th_num){ $(this).css("background-color","#000"); //или чего-нибудь еще творим с ячейкой. } }) }) }); }); 

    #yourtable_id - to ensure that the cycles and index search are performed correctly in case there are several tables.

        $('button').one('click', function() { $('#myTable tr:last').append($("<th></th>").text("someText")); }); 
      • You do not understand. When you click on the title for example 2nd column, the text should be added to every cell of the second column - Fuzzz3r
      • I apologize) - stck