正在获取$ this父级兄弟姐妹表的表行! [英] getting table row of $this parent siblings table !

查看:59
本文介绍了正在获取$ this父级兄弟姐妹表的表行!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表格下方有一个href链接,我希望能够通过单击该链接来操纵表格行,但我无法获取它们!

i have a href link under my table and i want to be able to manipulate table rows by clicking on that link but i cant get them !

这是我的html

<div>
  <div>  <a href="#remove" class="removelink" > remove </a> </div>

    <table>
    <tr> <td></td> </tr>
    </table>
 </div>

我想做类似的事情:

$('.removelink').click(function(){
$(this).parent().siblings('table tr:last').remove();
})

我可以通过以下方式到达餐桌

i can get to the table by

$(this).parent().siblings('table')

但是我无法通过类似的方式获取行

but i cant get rows by something like

$(this).parent().siblings('table tr')

推荐答案

您可以使用 find table进入tr:

$('.removelink').click(function(){
    $(this).parent().siblings('table').find('tr:last').remove();
});

这是一个工作示例.如果您的HTML结构始终与显示的完全一样,则可以使用 next() 代替siblings('table')用于较短的代码.

Here's a working example. If your HTML structure is always exactly as you've shown, you could use next() instead of siblings('table') for slightly shorter code.

您当前代码的问题是siblings('table tr')将查找div的同级项,即tr,而没有任何同级项!

The problem with your current code is that siblings('table tr') will look for a sibling of the div which is a tr, and there are none!

这篇关于正在获取$ this父级兄弟姐妹表的表行!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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