开发者

clone then alter table row before inserting back with jquery

I have 2 tables one, with a list of products to choose from and one with products chosen. I also have a link in each to add from one and delete from the other. When you delete from one of the tables I want to copy and insert into the other table but I need to change the link href before doing so, then add a click behavior to it.

Here is the table row I am cloning.

<tr> 
        <td><a href="/Partner/DeleteProduct/41/?ProductID=935ad105-xxxx-xxxx-xxxx-659cd4c55ec7"  class="delete"><img src="/Content/images/remove.png" alt="Del开发者_JS百科ete" /></a> <span id="705">GastroMend-HP </span></td> 
        <td>Designs for Health</td> 
</tr> 

Here is my code so far, which properly moves the row but worth the wrong link href, although I did properly change the img path like I wanted to (#Product is the table I am adding to).

$('a.delete').click( function(e){
var el = $(this)
  // hide the clicked row
  el.parent().parent().fadeOut();
      // this does my server work
      $.get(el.attr('href'), function(data) {
          // this is the row cloning part I need to tweak
          el.parent().parent().clone().insertAfter('#Product tr:first').find('img').attr('src','/Content/images/insert.png');
      });
  e.preventDefault();
});


Store it in a variable, then manipulate it before inserting.

var myclone = el.parent().parent().clone();

myclone.find('img').attr('src','/Content/images/insert.png');
myclone.find('a').attr('href','http://....');

myclone.insertAfter('#Product tr:first');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜