Reputation: 1165
How do I set text of a a certain cell (td) in a html table with jquery properly?
I've earlier created this row dynamically
$('#productOrderTable').append('<tr id="prodBasketPaymOptIdRow1" style="display:none"><td></td><td></td><td> i want to set text here </td></tr>');
So I have an id for the row and want to set text for the 3rd column in the table.
I know I can use span-tag instead to identify the td but it think its more simple this way since in reality I have more than one td in this row to change. If I use span-tag i need one for each td.
thanks in advance!!!
Upvotes: 0
Views: 1505
Reputation: 308
you can use last-child property :
$( "#prodBasketPaymOptIdRow1 td:last-child" ).text( "Your text" );
Upvotes: 0
Reputation: 1364
$( "#prodBasketPaymOptIdRow1 td:nth-child(2)" ).append( "Your text" );
Upvotes: 1
Reputation: 18158
$( "#prodBasketPaymOptIdRow1 td:nth-child(3)" ).text( "i want to set text here" );
https://api.jquery.com/nth-child-selector/
Upvotes: 1