如何使用jQuery删除td标签中的内容
问题描述:
我有一个像这样定义的表
I have a table defined like
<table>
<tr>
<td>
<input type='text' />
</td>
<td>
<button id ='first'>Button</button>
</td>
<td>
<input type='text' />
</td>
</tr>
$("#first").live('click',function(){
$(this).prev().remove();
$(this).remove();
});
如何删除td
中的上一个元素.但我不想删除td
How can i remove the previous element in the td
. But i don't want to remove the td
答
如果要删除该先前TD的完整内容(而不是特定的INPUT元素),则可以使用:
If you want to remove the complete contents of that previous TD (rather than a specific INPUT element), this will work:
$(document).on("click", "#first", function() {
$(this).closest("td").prev().empty();
});