如何使用jQuery删除td标签中的内容 [英] How to remove the content in the td tag using jquery

查看:131
本文介绍了如何使用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();
});

这篇关于如何使用jQuery删除td标签中的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆