jQuery删除类的最后一个孩子 [英] jQuery remove last-child of a class
问题描述
我正在处理动态表单,这些行具有父级下拉列表,并且当我们选择一个父级时,它将为子级数添加新的ROW,我为每个子级行指定了类.可以选择动态添加父行,依此类推.
I am working on a dynamic form, the rows are having parent dropdowns, and when we select a parent it adds new ROWs for number of childs, I have given classes to each child rows. There is option of dynamically adding a parent row, and so on.
到目前为止,添加和删除父行工作正常.我无法删除最后一个子行
So far adding and deleting the parent rows are working fine. I am having trouble removing the last child row
下面是关于如何创建行的粗略想法
below is a rough idea of how the rows are created, the
Row 1: <parent> select
Row 2: -<child> select
Row 3: -<child> select
Row 4: - Child Add row / Remove row
Row 5: <parent> select
Row 6: -<child> select
Row 7: - Child Add row / Remove row
Row 8: Parent Add row / remove row
更好的主意是屏幕截图
此表很简单,没有嵌套表,只有6列和12行,通过CSS缩进
This table is simple, no nested tables, only 6 columns and 12 rows, the indenting is done via css
现在,如果我在萤火虫控制台中使用$('tr.partnumber_2_sub');
,我可以看到类似的结果
Now if I use $('tr.partnumber_2_sub');
in console of firebug, i can see result like
Object[tr.partnumber_2_sub, tr.partnumber_2_sub, tr.partnumber_2_sub]
但是当我使用$('tr.partnumber_2_sub:last-child');
时,它会输出空对象.我想删除最后一个孩子,我猜是$('tr.partnumber_2_sub:last-child').remove();
,但是它不起作用.
but when i use $('tr.partnumber_2_sub:last-child');
it output empty object. I want to remove the last child and my guess was to $('tr.partnumber_2_sub:last-child').remove();
but it is not working.
编辑
感谢最后一行的答案,但我意识到我的孩子添加行/删除行在tr上也有相同的类.现在我必须删除倒数第二个元素
Thanks for the answers for the last row, but i realized that my child add row / del row are also having same class on tr. Now i have to remove 2nd last element
编辑
好的,我在子行的tr上添加了额外的类,并且没有添加子行的添加/删除,所以现在我可以单独使用它们了.改回标题并接受答案.
Okay, i have added extra class on tr of child row, and didnt added it add / del of child so now I can use them separately. changed back the title and accepted the answer.
比大家
推荐答案
尝试
$('tr.partnumber_2_sub').last().remove()
这篇关于jQuery删除类的最后一个孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!