如何在TR的最后一个TD中添加事件或将ID属性添加到IMG标签
how add event or add id attribute to img tag in last td in tr
我需要将属性ID设置为以下突出显示的img标签或找到突出显示的img标签并添加onclick事件。我怎样才能用jQuery做到这一点?
<img src="/site/control/uploader/phpuploader/resources/stop.png" ...
<tbody>
<tr class="AjaxUploaderQueueTableRow" style="background-color: rgb(255, 255, 255);">
<td style="white-space: nowrap;">
<img src="/site/control/uploader/phpuploader/resources/circle.png" title="" width="16" height="16">
</td>
<td style="width: 456px;">Tales from the Dark 1 (2013).jpg</td>
<td style="white-space: nowrap;">
<img src="/site/control/uploader/phpuploader/resources/stop.png" title="Remove" width="16" height="16" style="cursor: pointer;">
</td>
</tr>
</tbody>
我不知道
什么时候你想这样做,但这将使用jquery设置id:
$('tr.AjaxUploaderQueueTableRow img:last').attr('id', 'yourID');
要找到最后一个 td,然后找到 img 标签,因为 img 可能不是最后一个:
$('tr.AjaxUploaderQueueTableRow td:last img').attr('id', 'yourID');
如果你想点击它并添加一个"突出显示"类,那就是:
var lastTlbImg = $('tr.AjaxUploaderQueueTableRow td:last img');
lastTlbImg.click(function(){
lastTlbImg.addClass('highlight');
})
更新
http://jsfiddle.net/kasperfish/2FCv6/2/
$("table:first tr td:last-child img").attr('id','blue').on('click', function(){
alert('clicked');
});
相关文章:
- 动态添加id's到输入字段
- 通过Couchdb中的更新处理程序添加id和author字段
- 如何在CKEditor中为图像添加ID
- 添加ID's在一个P HTML标签中的一个翡翠模板中
- 向Fabric.js元素添加ID
- 如何添加id和额外的参数到一个放大弹出iframe与youtube视频,所以我可以控制与API youtube播放器
- 创建折叠选项卡并动态添加 ID 和指向 jQuery 中 ID 锚点的链接
- 使用 for 循环,如何迭代对象以向其添加 id 属性
- 在“挖空”中添加 ID
- 避免在向标记添加 ID 时触发 DOMSubtreeModified 事件
- 我无法在 foreach 中向对象添加 ID
- 使用主干视图在模板上动态添加 ID 和类
- 在Angular对象中循环时向HTML添加id
- 为Datatable中的行添加id
- 使用jQuery向子级添加id
- 如何仅在li元素存在的情况下向pre元素添加id
- 如何使用javascript从最近的li元素向pre-tag添加id
- 如何在javascript中向输入字段添加ID
- jQuery或Javascript单击函数更改或添加id
- 将jquery变量连接到字符串,以便添加id's转换为动态生成的输入字段