开发者

Can I add a unique id attribute to a td from jquery?

开发者 https://www.devze.com 2023-01-11 12:23 出处:网络
I have a table being populated and I would like the td id to be the id number for the data that开发者_开发问答 was returned.How do I assign an id to a td from jquery?

I have a table being populated and I would like the td id to be the id number for the data that开发者_开发问答 was returned. How do I assign an id to a td from jquery?

var $tr = $('<tr><td class="name"></td></tr>').insertAfter('#newTable tr:last');
$tr.find('.name').html(data.Name);
//How do I assign data.id to <td class="name"> ?


This should work:

$tr.find('.name').attr('id', data.id).html(data.Name);


$('.name').attr('id', data.id)
0

精彩评论

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