找到有条件的下一个元素

时间:2013-02-06 15:03:15

标签: javascript jquery

分层树:

  mouse (depth:0, sequence:0)
    *   organ system (depth:1, sequence:1)
        o   visceral organ (depth:2, sequence:2)
              urinary system (depth:3, sequence:3)
              mesentery (depth:4, sequence:4)
                  *   rest of mesentery (depth:5, sequence:5)
                  *   urogenital mesentery (depth:5, sequence:6)
              metanephros (depth:4, sequence:7)
                  *   renal capsule (depth:5, sequence:8)
                  *   nephrogenic zone (depth:5, sequence:9)

我有以下代码,它应检索所选节点后FIRST下一个节点的名称,该节点与所选节点的深度相同,且序列值应大于selected_node_sequence:

/** node id has the same value as node_depth **/

  var selected_node_depth = parseInt($j(element).attr('APO_DEPTH'));
  var selected_node_sequence = parseInt($j(element).attr('APO_SEQUENCE'));

  var first_next_node_with_same_depth = $j("#"+selected_node_depth).next().attr("name"); [where first_next_node_with_same_depth sequence value > selected_node_sequence]

例如,如果'selected_node'=肠系膜,'first_next_node_with_same_depth'应该是后肾

非常感谢任何关于如何做到这一点的建议

1 个答案:

答案 0 :(得分:0)

使用纯JS获取下一个节点的简单方法:

(yournode).nextElementSibling

显然,您可以使用getElementById语句来获取节点,或者如果您已将其存储在代码中的其他位置,则可以使用节点本身。如果您需要/提供更多信息,很乐意改进这个答案。

相关问题