简体   繁体   English

如何从下到上迭代子元素的

[英]how to iterate element child's from bottom to top

I have a table. 我有桌子

I will now iterate the <tr> elements which are child's from the element <tbody> from bottom to top. 现在,我将从底部到顶部的元素<tbody>迭代作为子元素的<tr>元素。

This code will iterate the child's from top to bottom. 这段代码将从头到尾迭代孩子的。

$.each($('#tbody').children(), function( key, value ) {
    // do magic
});

$('#tbody').children().reverse() will not work... $('#tbody').children().reverse()将不起作用...

You can try 你可以试试

$('#tbody').children().get().reverse()

ie

$.each($('#tbody').children().get().reverse(), function( key, value ) {
    // do magic
});

Demo: Fiddle 演示: 小提琴

var children = $('#tbody').children();
for (var i = children.length - 1; i >= 0; i--) {
  //Do something with children[i]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM