Search code examples
jquerydisplaytag

Add new row in a table after each row


Table:

<table id='t1' style='border:1px solid #000000'>
    <tr>
      <td><span id='flight_1'>1</span></td><td>1</td>
    </tr>   

    <tr>
      <td><span id='flight_2'>2</span></td><td>2</td>
    </tr>  

    <tr>
      <td><span id='flight_99'>99</span></td><td>99</td>
    </tr> 
</table>

I want to search for each 'flight_xx' id and then create a new row after the row belonging to the 'flight_xx' id.

Is this possible using jQuery?

The table is created using the DisplayTag library and I can't figure out how to do it.


Solution

  • Try:

    $('span[id^="flight"]').closest('tr').after('<tr>This is a new tr</tr>');
    

    That would add a new row after rows that contain spans having ids that start with flight.