html - jQuery .text content from one table-cell to another each row -


i have dynamic table rows. try ".tags"-td-content , write ".tagsnew"-td in each row.

  <tr>      <td class="td1">         date 1      </td>      <td class="td2">         text 1         <div class="tags"><a href="http://home1.com">row_1_tag</a></div>      </td>      <td class="tagsnew">      </td>   </tr>    <tr>      <td class="td1">         date 2      </td>      <td class="td2">         text 2         <div class="tags"><a href="http://home2.com">row_2_tag</a></div>      </td>      <td class="tagsnew">      </td>   </tr>    <tr>      <td class="td1">         date 3      </td>      <td class="td2">         text 3         <div class="tags"><a href="http://home3.com">row_3_tag</a></div>      </td>      <td class="tagsnew">      </td>   </tr>    ... 

desired result:

  <tr>      <td class="td1">         date 1      </td>      <td class="td2">         text 2         <div class="tags"><a href="http://home1.com">row_1_tag</a></div>      </td>      <td class="tagsnew">          row_1_tag   /* needed */      </td>   </tr>    <tr>      <td class="td1">         date 2      </td>      <td class="td2">         text 2         <div class="tags"><a href="http://home2.com">row_2_tag</a></div>      </td>      <td class="tagsnew">          row_2_tag   /* needed */      </td>   </tr>    ... 

this script:

<script>  function gettag(){      row = $("tr");     tagneeded = $('tr .tags').text()      $.each(row, function() {         $('.tagsnew').text(tagneeded);       }); }  </script>  

the code works, need the .tags-content specific row. function pastes content rows .tagsnew table-cell

this happens above code

<!-- result function gettag() -->   <tr>      <td class="td1">         date 1      </td>      <td class="td2">         text 1         <div class="tags"><a href="http://home1.com">row_1_tag</a></div>      </td>      <td class="tagsnew">          row_1_tag row_2_tag row_3_tag      </td>   </tr> 

any appreciated

you can use set relevant specific text:

$('.tagsnew').text(function(){     return $(this).closest('tr').find('.tags').text(); }); 

Comments