nick
nick

Reputation: 891

Can I use jquery or javascript to append data to a specific td in a row?

I have a table that looks something like

<tr class = 'list'>
   <td> 
     <span> some content</span>
    </td>
    <td> 
     <span> some content</span>
   </td>
    <td> 
     <span> some content</span>
   </td>
</tr>

I want to use jquery/javascript to append some text to the third <td> if it is null. I know I can use something like

$("td.quantity").append("stuff you want to append");

to append to td's of a class, but I can't really change how these are drawn to add a class there. Is there any way to do it like by index of sorts, even checking if the td is null would work, as there is only one that can be.

Upvotes: 0

Views: 83

Answers (1)

nicael
nicael

Reputation: 19015

eq() is something which is going to help here.

$(".list td").eq(2).append("stuff you want to append");

Upvotes: 3

Related Questions