java
java

Reputation: 1165

Set text of a certain td in a html-table - jquery

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

Answers (3)

Pratik Deshmukh
Pratik Deshmukh

Reputation: 308

you can use last-child property :

$( "#prodBasketPaymOptIdRow1 td:last-child" ).text( "Your text" );

Upvotes: 0

Bhavin Solanki
Bhavin Solanki

Reputation: 1364

$( "#prodBasketPaymOptIdRow1 td:nth-child(2)" ).append( "Your text" );

For Referance

Upvotes: 1

jeffery_the_wind
jeffery_the_wind

Reputation: 18158

$( "#prodBasketPaymOptIdRow1 td:nth-child(3)" ).text( "i want to set text here" );

https://api.jquery.com/nth-child-selector/

Upvotes: 1

Related Questions