0

I'm trying to add more rows into a TD item. So, when i click a link, all TD would get an extra TR.

<td>
    <tr>Test</tr>
    <tr>Test</tr>
    <tr>Test</tr>
</td>

<td>
    <tr>Test</tr>
    <tr>Test</tr>
    <tr>Test</tr>
</td>

<td>
    <tr>Test</tr>
    <tr>Test</tr>
    <tr>Test</tr>
</td>

I've been trying with this,

$('#add_rows').click(function()
{
    $("td").append("<tr>Test</tr>");
});

But it won't work... what am i doing wrong?

2
  • 3
    Your basic HTML knowledge is wrong. <TD> tags are contained by a <TR> not the other way around. Commented Sep 9, 2012 at 14:53
  • link is not added in the sample code, no need as alert etc works. TD or TR one way or another, css takes care of how it should work. Commented Sep 9, 2012 at 14:54

1 Answer 1

1

Your table structure is incorrect. <tr> are Table Rows, so, they have <td> (Table Data) items. Your selector expression is correct, but as I said, your structure is incorrect, so your code not works. Take a look: http://jsfiddle.net/h6K66/

So, you just need to invert your structure.

Sign up to request clarification or add additional context in comments.

2 Comments

Yes, if i have an alert, it shows. $('#add_rows').click(function() { $("tr").append("<td>Test</td>"); alert('test'); });
As I said, your problem is your table structure. Change it to the correct way (<td> inside <tr>) and your code will work.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.