2
<div id="myDiv1">
<table>
<tr id="row">
</table>
</div>
<div id="myDiv2">
<table>
<tr id="row">
</table>
</div> 

Here I need to append different '<td>'s into these two . I have tried this code $('#row').append() but its only putting '<td>'s into the row of myDiv1. Can anyone help me to do this.

tvshajeer
  • 1,299
  • 2
  • 12
  • 26

2 Answers2

2

There are multiple erros in your markup:

  1. No closing <tr>-tags
  2. Non-Unique ID's

So the ID-Attribute has to be unique in its scope. See here for further information.

Your mark-up should be looking like this:

<div id="myDiv1">
    <table>
        <tr class="row">
        </tr>
    </table>
</div>
<div id="myDiv2">
    <table>
        <tr class="row">
        </tr>
    </table>
</div> 

With the right markup your jQuery just works fine:

$('.row').append('<td>test</td>');

Demo

empiric
  • 7,825
  • 7
  • 37
  • 48
0

You should change the ID attribute to a class.

But why are you using two tables? maybe you need to clean the html and make it as bellow.

<div id="myDiv1">
    <table>
        <tr class="row">
        </tr>
        <tr class="row">
        </tr>
    </table>
</div> 
bumstyla
  • 19
  • 6